in reply to replace multiple newline characters

Since you have the input lines as an array, easiest would be to use grep.
my @newlines = grep{/\S/}@lines; #move only lines that have #a non whitespace char to the left or @lines = grep{/\S/}@lines;
Update:
Normally when reading text files, I read it line by line instead of creating an in memory array.

For input I normally allow any number of "unseeable" whitespace chars. A blank line often may have an extra space in it that you can't see, especially if the input file is something that a human might edit.

while (<FH>) # update: was: while (my $line = <FH>) # don't really need "my line" here { next unless /\S/; #skip blank lines next if /^\s*#/; #skip comments, or whatever... blah, blah }