$CHUNK_SIZE = 4096; open FILE, $file or die "$!\r\n"; while (read FILE, $chunk, $CHUNK_SIZE) { # split the chunk into a list of parts, keeping # the line endings in the array @parts = split /(\r\n?|\n)/, $chunk; if (defined $partial) { $part[0] = $partial . $part[0]; undef $partial; } # if the last part is not a line ending, then # the line could potentially be continued in # the following chunk if ($parts[-1] !~ /^\r\n?|\n$/) { $partial = pop @parts; } push @lines_and_endings, @parts; } push @lines_and_endings, $partial if defined $partial; close FILE; print @lines_and_endings; @just_lines = grep { ! /^\r\n?|\n$/ } @lines_and_endings;