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


in reply to out of memory error while reading file contents into an array

You should iterate over the filehandle directly.

use strict; use warnings; my $filename = 'filename.txt'; open(my $fh, $filename) or die "cann't open file filename : $!\n"; while (<$fh>) { my $line = $_; next if ($line =~ /^\s*$/); # skip blank lines chomp($line); # remove line endings # .... do your coding here on each line } close($fh);