in reply to replace multiple newline characters

Since you're already reading the entire input at once, read it all into a scalar with something like
    my $input = do { local $/;  <FILE>; };
and then

c:\@Work\Perl\monks>perl -wMstrict -le "my $input = qq{line1\nline2\n\nline4\n\n\nline7\nline8\n}; print qq{[[$input]]}; ;; $input =~ s{ ^ \s* \n }{}xmsg; print qq{<<$input>>}; " [[line1 line2 line4 line7 line8 ]] <<line1 line2 line4 line7 line8 >>

Update 1: Or, if you need to read all the lines of the file as separate lines and keep them that way, try
    my @lines = grep !m{ \A \s* \Z }xms, <FILE>;

c:\@Work\Perl\monks>perl -wMstrict -le "my @lines = ( qq{line1\n}, qq{line2\n}, qq{\n}, qq{line4\n}, qq{ \t\n}, qq{\t \t \n}, qq{line7\n}, qq{line8\n}, ); print qq{[[@lines]]}; ;; @lines = grep !m{ \A \s* \Z }xms, @lines; print qq{<<@lines>>}; " [[line1 line2 line4 line7 line8 ]] <<line1 line2 line4 line7 line8 >>

Update 2: Slight formatting fix to code in Update 1; no functional change.

Update 3: Rather than using
    !m{ \A \s* \Z }xms
to grep lines in the code in Update 1, I think I'd prefer
    m{ \S }xms
as used by Marshall here; don't know why I didn't use it in the first place. Note that no logical negation is needed.


Give a man a fish:  <%-{-{-{-<