in reply to Problem with reading the total file into variable

Others have pointed out some of the places where you have gone wrong in your original code. Here, I'd like to point out a recommended method from the FAQ.

If, for some odd reason, you really want to see the whole file at once rather than processing line-by-line, you can slurp it in (as long as you can fit the whole thing in memory!):

open my $in, '<', $file or die "Can't read old file: $! +" open my $out, '>', "$file.new" or die "Can't write new file: $ +!"; my $content = do { local $/; <$in> }; # slurp! # do your magic here print $out $content;

There really is lots of good stuff in the FAQ and if you will be doing any work with files at all, then FAQ 5 (linked above) will serve you well. Good luck.