title: Using a variable as a method name in Perl
body: <p>I have a perl script (simplified) like so:</p>
  
  <pre><code>my $dh = Stats::Datahandler-&gt;new(); ### homebrew module
  
  my %url_map = (
      '/(article|blog)/' =&gt; \$dh-&gt;articleDataHandler,
      '/video/' =&gt; \$dh-&gt;nullDataHandler,
  ); 
  </code></pre>
  
  <p>Essentially, I'm going to loop through <code>%url_map</code>, and if the current URL matches a key, I want to call the function pointed to by the value of that key:</p>
  
  <pre><code>foreach my $key (keys %url_map) {
      if ($url =~ m{$key}) {
          $url_map{$key}($url, $visits, $idsite);
          $mapped = 1;
          last;
      }
  }
  </code></pre>
  
  <p>But I'm getting the message:</p>
  
  <p><code>Can't use string ("/article/") as a subroutine ref while "strict refs" in use at ./test.pl line 236.</code></p>
  
  <p>Line 236 happens to be the line <code>$url_map{$key}($url, $visits, $idsite);</code>.</p>
  
  <p>I've done similar things in the past, but I'm usually doing it without parameters to the function, and without using a module.</p>