title: Perl: moving files into dedicated folders
body: <p>I have a perl script to move files from  one directory (/folder/) to another (/folder2/) and then if the file name (File20.doc) matches the folder name (folder/file20) exactly it will put the file into that folder.</p>
  
  <p>What I need is if part of the file name matches the folder it will put that file into that folder. For example if the file is named file24.doc it will put that file into file20.</p>
  
  <p>Here is the script I have so for that will match extact file names to matching folders.</p>
  
  <pre><code>#!/usr/bin/perl
  use warnings;
  use File::Copy;
  
  my $srcdir = "/folder/";
   my $dest = "/folder2/";
  
  opendir(DIR, $srcdir) or die "Can't open $srcdir: $!";
   @files = grep {!/^\.+$/ }  readdir(DIR);
  
  
   foreach my $file (@files) {
  
   my $old = "$srcdir/$file";
  
  
   move($old, $dest) or die "Move $old -&gt; $dest failed: $!";
  
  
   }   
  close(DIR);
  
  print "
  
  -Complete";
  exit;
  </code></pre>