in reply to Re^2: Strange behavior with STDINin thread Strange behavior with STDIN
$str =~ s/\s+\z//; is a far better (and more portable) solution.