sub trim { my ($string) = @_; $string =~ s{ \A \s+ }{}xms; $string =~ s{ \s+ \z }{}xms; return $string; }