my $var = ' some words '; $var =~ s/\A \s* (.*) \s* \z /$1/x;