open IMAGEHASH, "results.txt" or die "Couldn't open file:$!"; my %image_hash = ( ); my $search = undef; my $replace = undef; while () { ($search, $replace) = ($_=~m/(.*) (.*)/); if ($search ne '' && $replace ne '') { $image_hash{$search} = $replace; } } opendir (GIFDIR, "/home/tony/perl/pmbencor") || die ("Cannot open directory."); my @the_files = grep { $_ ne '.' && $_ ne '..' } readdir(GIFDIR); closedir GIFDIR; foreach my $file (@the_files) { foreach $key (keys %image_hash) { $file=~ s/$key/$image_hash{$key}/g; } } mkdir ("newdir", 0777) || print $!; opendir (NEWDIR, "/home/tony/perl/newdir") || die ("Cannot open directory."); use Cwd; my $here = cwd; my $there = '/home/tony/perl/newdir'; use File::Copy; foreach my $file (@the_files) {move ($here, $there)} closedir NEWDIR;