#replace 0 or more whitespaces at the beginning # or 0 or more whitespaces at the end # with nothing $string =~ s/^\s+|\s+$//g;