$str =~ s/^\s+//; # no whitespace at front $str =~ s/\s+$//; # no whitespace at rear