title: Find files matching pattern in the file array
body: <p>I have code in perl as below. Trying pick files which matches the pattern.</p>
  
  <pre><code>opendir ERR_STAGING_DIR, "$ERR_STAGING" or die "$PID: Cannot open directory $ERR_STAGING";
  @allfiles = grep !/^$ERR_STAGING\/\./, map "$ERR_STAGING/$_", readdir(ERR_STAGING_DIR);
  closedir(ERR_STAGING_DIR);
  
  $ERR_FILETYPE = basename ($ERR_FILETYPE);
  
  $ERR_FILETYPE =~ s/\./\\\./g;
  $ERR_FILETYPE =~ s/\*/\*/g;
  
  @file_type = grep /^$ERR_STAGING/./$ERR_FILETYPE$/, @allfiles;
  $numelements = @file_type;
  if ($numelements &lt;= 0) {
      print LOG "$PID: No files match specified pattern, exiting.\n";
      &amp;HandlerDie($NO_FILE_TYPE, $current_poid);
  }
  </code></pre>
  
  <p>Here is what I'm doing above. Grep all files from ERR_STAGING directory. grep files matching pattern <code>'BVN*.fin.bc_lerr.xml.bc'</code> e.g <code>BVN_201608250000.fin.bc_lerr.xml.bc</code> and do something with the file. However the above code is returning files which doesn't match pattern too, it also pickup some temp directories.</p>