1st line 2nd line, next line is just a newline 4th line, next line spaces and newline 6th and last line #### use strict; use warnings; my $inFile = q{spw592594.dat}; open my $inFH, q{<}, $inFile or die qq{open: $inFile: $!\n}; while (<$inFH>) { chomp; next unless $_; print qq{-->$_<--\n}; } close $inFH or die qq{close: $inFile: $!\n}; #### -->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- --> <-- -->6th and last line<-- #### ... while (<$inFH>) { chomp; # reject if 0 or more spaces anchored to start and end next if m{^\s*$}; print qq{-->$_<--\n}; } ... #### -->1st line<-- -->2nd line, next line is just a newline<-- -->4th line, next line spaces and newline<-- -->6th and last line<--