文字列から前後の空白を削除する
#!/usr/bin/perl $str = " aaa bbb ccc "; print "With spaces: >>>", $str, "<<<\n"; $str =~ s/^\s+//; $str =~ s/\s+$//; print "Without spaces: >>>", $str, "<<<\n";
With spaces: >>> aaa bbb ccc <<<
Without spaces: >>>aaa bbb ccc<<<
はては記法のせいで正しく表現されていないが、最初のprintの結果は前後に4つずつスペースが付く。