push @strings, 'nospace'; push @strings, 'trailingspace '; push @strings, ' leadingspace'; push @strings, 'internal space'; push @strings, ' surroundedbyspace '; push @strings, ' spaces every where '; for my $wtf (@strings) { print "Before: '$wtf'\n"; $wtf =~ s/\s*(.*?)\s*/$1/; print "After: '$wtf'\n\n"; }