$line =~ s![\r\n]+$!!; # just newlines $line =~ s!\s+$!!; # all kinds of whitespace