Perl code use strict; use warnings; my $str=" \n aaa bbb\n "; $str=~s/^\s+|\s+$//g; print($str); ^D aaa bbb