use strict; use warnings; use 5.010; use Benchmark qw(:all :hireswallclock) ; my $inputA = "X".(" \t" x 200000)."A"; my $inputB = "X".(" \t" x 200000)."B"; my $c1A = <<'CODE'; my $s = $inputA; $s =~ s/[\s\u200c]+A/ A/; CODE my $c1B = <<'CODE'; my $s = $inputB; $s =~ s/[\s\u200c]+A/ A/; CODE my $c2A = <<'CODE'; my $s = $inputA; $s =~ s/(?<=\S)[\s\u200c]+A/ A/; CODE my $c2B = <<'CODE'; my $s = $inputB; $s =~ s/(?<=\S)[\s\u200c]+A/ A/; CODE timethis(50_000_000,$c1A); timethis(50_000_000,$c1B); timethis(50_000_000,$c2A); timethis(50_000_000,$c2B);