use strict; use warnings; use Benchmark qw(:all :hireswallclock) ; our $inputA = "X".(" \t" x 10000)."A"; our $inputB = "X".(" \t" x 10000)."B"; our $m1A = 0; our $m1B = 0; our $m2A = 0; our $m2B = 0; my $c1A = <<'CODE'; my $s = $inputA; $m1A++ if ($s =~ s/[\s\u200c]+A/ A/g); CODE my $c1B = <<'CODE'; my $s = $inputB; $m1B++ if ($s =~ s/[\s\u200c]+A/ A/g); CODE my $c2A = <<'CODE'; my $s = $inputA; $m2A++ if ($s =~ s/(?<=\S)[\s\u200c]+A/ A/g); CODE my $c2B = <<'CODE'; my $s = $inputB; $m2B++ if ($s =~ s/(?<=\S)[\s\u200c]+A/ A/g); CODE timethis(100_000,$c1A); timethis(100_000,$c1B); timethis(100_000,$c2A); timethis(100_000,$c2B); print "M1A: $m1A\n"; print "M1B: $m1B\n"; print "M2A: $m2A\n"; print "M2B: $m2B\n";