use File::Slurp; my $string = read_file("yourfile"); write_file("yourfile.bak", $string); $string =~ s/everything/otherthings/g; $string .= "endbit\n"; write_file("newfile", $string);