# Assumes you are using strict -- RIGHT? { # Need to add tags of and <\vom> at the start and # end of the file. # Changing '\' to '\\' is not wrong, but you can also use # '/' on Windows. Perl handles it just fine, and it's a lot # easier to read. It's optional here since you're not dealing # with the filenames directly. $out->[1] =~ s{\\}{/}g; # First, create a backup name and rename the original file. This # creates your backup file, and we'll create your "original" in # a moment. my $bk = $out->[1] . ".bk"; rename $out->[1], $bk; # Open the backup for input. open my $f, '<', $bk or die $!; my $data; # Use this to capture data. # Old-style slurp mode. { local $/ = undef; $data = <$f>; } # Now open the original filename, reusing the filehandle, and # write to it. open $f, '>', $out->[1] or die $!; print $f "\n", $data, "\n\n"; close $f; # All done. }