in reply to Re: Trimming whitespaces methods
in thread Trimming whitespaces methods

In order for the code to be truly equivalent the s modifier should be used on the substitution or a newline may break it.

$_ = " foo\nbar "; s{ ^\s* (\S.*?) \s*$ }{$1}x; print "<$_>"; __END__ < foo bar >
I assume you added the \S in the pattern as an improvement, but it should perhaps be noted that it has the effect of leaving a line of only whitespaces untouched, whereas the other ways don't.