while (my $line = <$fh_in>) { my $text = $line; chomp ($text); #Strip/remove whitespace between lines of text file; while () { print if (!/^\s*$/); } print $fh_out "$text\n"; #Save stripped results; } #### while (my $line = <$fh_in>) { print $fh_out $line if (!/^\s*$/); } #### while (my $line = <$fh_in>) { print $fh_out $line if $line !~ /^\s*$/; }