use strict; use warnings; my $word = 'Wilmer",'; $word =~ s/^ \W*? # ignore any leading punc ( \w .*? ) # swallow everything lazily (?: \W+ )? $ # ignore any trailing punc /$1/x; print $word; #### $word =~ s/(?:^\W+)|(?:\W+$)//g; #### Rate capture non_capture capture 16561/s -- -28% non_capture 22861/s 38% --
## $word =~ s/(?:^\W+)|(?:\W+$)//g; ##
## Rate capture non_capture capture 16561/s -- -28% non_capture 22861/s 38% --