$_ = ' blee blah '; s/\s*(.*?)\s*/$1/; print "matched '$&'; retained '$1'; str is '$_'\n"; #### matched ' '; retained ''; str is 'blee blah ' #### s/^\s+//; s/\s+$//; #### [matt@blade8 matt]$ perl -MBenchmark -e '@list1 = @list2 = map { " "x rand(100) . "some text" . " "x rand(100) } 1 .. 100; timethese( 100_000, { single_regexp => sub { return map { s/^\s*(.+?)\s*$/$1/; $_ } @list1 }, dual_regexp => sub { return map { s/^\s+//; s/\s+$//; $_ } @list2 } } ); ' Benchmark: timing 100000 iterations of single_regexp, dual_regexp... single_regexp: 56 wallclock secs (56.04 usr + 0.00 sys = 56.04 CPU) @ 1784.44/s (n=100000) dual_regexp: 17 wallclock secs (18.63 usr + 0.00 sys = 18.63 CPU) @ 5367.69/s (n=100000)