in reply to Re^2: Strange behavior with STDIN
in thread Strange behavior with STDIN

$str =~ s/\s+\z//; is a far better (and more portable) solution.