http://www.perlmonks.org?node_id=184785


in reply to Memory use when reading a text file

This is related to your use of for(each), which tries to store the whole file in a temporary array in memory.

Try:

while( my $line = <INP> ){ ... }
instead. This will simply copy each line into memory as needed.