title: Perl search lookup efficiency
body: <p>I have a batch of urls that I have to search through the database for a match or rather if the url contains the url in the database.</p>
  
  <p>An example of a url is</p>
  
  <pre><code>http://www.foodandnuts.com/login.html
  </code></pre>
  
  <p>The database has a table filled with urls</p>
  
  <p>Currently my script created a array at the start that has all the urls in my database</p>
  
  <pre><code>my $results = $dbh-&gt;selectall_hashref('SELECT * FROM urltable;', 'url');
  foreach my $j (keys %$results) {
  push(@urldb, $j);
  }
  </code></pre>
  
  <p>It will then go through the array to see if the url contains the url from the database</p>
  
  <pre><code>    foreach(@urldb){
              if($searchedurl=~ /$_/){
  #do things here
  }}
  </code></pre>
  
  <p>The problem is that is extremely slow as the array has more than 10000 urls so each searched url has to go through that array. Is there any way to make this faster?</p>