title: How do I build Perl regular expressions dynamically?
body: <p>I have a Perl script that traverses a directory hierarchy using File::Next::files.  It will only return to the script files that end in ".avi", ".flv", ".mp3", ".mp4", and ".wmv."  Also it will skip the following sub directories:  ".svn" and any sub directory that ends in ".frames."  This is specified in the <code>file_filter</code> and <code>descend_filter</code> subroutines below.</p>
  
  <pre><code>my $iter = File::Next::files(
          { file_filter =&gt; \&amp;file_filter, descend_filter =&gt; \&amp;descend_filter },
          $directory );
  
  sub file_filter { 
      # Called from File::Next:files.
      # Only select video files that end with the following extensions.
      /.(avi|flv|mp3|mp4|wmv)$/
  }
  
  sub descend_filter { 
      # Called from File::Next:files.
      # Skip subfolders that either end in ".frames" or are named the following:
      $File::Next::dir !~ /.frames$|^.svn$/
  }
  </code></pre>
  
  <p>What I want to do is place the allowed file extensions and disallowed sub directory names in a configuration file so they can be updated on the fly.</p>
  
  <p>What I want to know is how do I code the subroutines to build regex constructs based on the parameters in the configuration file?  </p>
  
  <pre><code>/.(avi|flv|mp3|mp4|wmv)$/
  
  $File::Next::dir !~ /.frames$|^.svn$/
  </code></pre>