use strict; use warnings; use Benchmark qw(cmpthese); my $testStr = (' ' x 1000) . 'x' . (' ' x 1000); cmpthese ( -1, { sExNibble => "sExNibbleRegex ('$testStr');", singleNibble => "singleNibbleRegex ('$testStr');", single => "singleRegex ('$testStr');", mExNibble => "mExNibbleRegex ('$testStr');", multiNibble => "multiNibbleRegex ('$testStr');", multi => "multiRegex ('$testStr');", } ); sub sExNibbleRegex { my ($string) = @_; $string =~ s/^\s|\s$|\s+$//g; } sub singleNibbleRegex { my ($string) = @_; $string =~ s/^\s|\s$//g; } sub singleRegex { my ($string) = @_; $string =~ s/^\s+|\s+$//g; } sub multiNibbleRegex { my ($string) = @_; $string =~ s/\^s//g; $string =~ s/\s$//g; } sub mExNibbleRegex { my ($string) = @_; $string =~ s/\^s//g; $string =~ s/\s$//g; $string =~ s/\s+$//g; } sub multiRegex { my ($string) = @_; $string =~ s/\^s+//g; $string =~ s/\s+$//g; }