Short answer--don't slurp the entire file.
Longer answer. If the text you are removing extends across multiple lines, you may be able to use paragraph mode ($/ = ' ';) to effect processing the file in smaller chunks.
If not, then you will need to use something like the sliding buffer technque demonstrated in Re: split and sysread() and towards the end of Optimising processing for large data files..
There are also other discussions of the "sliding buffer" technique on this site--try a super search for that term.
In reply to Re: Running out of memory...
by BrowserUk
in thread Running out of memory...
by knewter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |