for ($i=0, @chunk = (); !eof(IN) && $i < 10; $i++) { $chunk[$i] = ; } #### # Untested, but you get the idea while (read(IN, $buf, 1024, length($buf))) { while ($buf =~ s/^([^\r\n]*)[\r\n]+//) { handle_line($1); } }