$x =~ s/^\s+//; $x =~ s/\s+$//;
换句话说,从字符串中删除所有前导和尾随空格.
$x =~ s/^\s+|\s+$//g;
要么
s/^\s+//,s/\s+$// for $x;