in reply to Applying a regex across multiple files

Updated from Q & A this is a futher answer to a post in Q & A Apply regex to entire file, not just individual lines ? which was turing into a conversation better suited to this forum.

I'm not sure exactly what problem you're still experiencing, but the following seems to do what you're asking for.

#!/usr/bin/perl -w my $raw = 'c:/temp/delete.me'; my $out = 'c:/temp/newfile'; my $lines; { open (RAW, "<$raw") or die "Couldn't open $RAW"; local $/ = undef; $lines = <RAW>; close RAW; } $lines =~ s/^unwantedstuff//msg; $lines =~ s/moreunwantedstuff//msg; open (OUT, ">$out") or die "Couldn't open $out for writing"; print OUT $lines; close OUT;
Note the added /g modifier, if you want to get all occurrances of a peice of text, you probably need that as well.

I put the part that reads the file into a block so that making the $/ variable local is restricted to that section of the program. That's probably overkill if your entire script is not much bigger than this. If you start writing longer scripts, the fact that you've changed the value of this predefined global could give you problems. If you put it in a separate block as I've done here, it isolates the rest of the program from the effects of that.

Nuance

Baldrick, you wouldn't see a subtle plan if it painted itself purple and danced naked on top of a harpsichord, singing "Subtle plans are here again!"