locate the source directory and get the list of files there establish the name of the destination directory, and create it if necessary if $source_dir has subdirectories { create them as needed in the $dest_dir } for $infile ( @sourc_files ) { $outfile = $infile; $outfile =~ s{$source}{$dest}; # might be unnecessary? open(IN,"<","$source_dir/$infile"); open(OUT, ">","$dest_dir/$outfile"); while () { s/$source/$dest/g; print OUT; } close IN; close OUT; }