You're doing it wrong then.
#!/usr/bin/perl use Benchmark; sub trim { my $s=shift; $s =~ s/^[\s\u200c]+|[\s\u200c]+$//g; return $s; } timethis(100, sub { trim("x" . " " x 20000 . "x"); });
You're doing it wrong then.
With Perl 5.18 I get 2.65/s on a fast iMac.