while (<$fh>) { s/\s+\z//; # More flexible than chomp. ... }