Change foreach to while, to start.
If that doesn't fix things, only then worry about flushing buffers (which are probably 4k, so not the source of your memory problems.)
Internally, foreach builds the entire list in memory and only then starts processing it. while processes it a record at a time. The latter is almost always the way to go when reading from a file.
In reply to Re: perl is allocating massive memory
by chromatic
in thread perl is allocating massive memory
by chuckd
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |