use File::Slurp: # get one file here, as $file my($bakfile, $file, $text); # maybe set up file renaming with something like this... ($bakfile = $file ) =~ s/\.([^.]+)$/\.bak/; # then, the main bit $text = read_file($file); $text =~ s/this/that/smg; rename($file, $bakfile); write_file($file, $text); #### use Perl6::Slurp; #<= only handles input at present use File::Slurp; # permits writing. # and then.... .... $text = slurp($file); $text =~ s/$this/$that/smg; ... with renaming here ? (see above). write_file($file, $text);