while (my $line = ) { chomp; # Or more thorough: $line =~ s/\s+\z//; next if !length($line);