$ perle ' my $x = "AB"; my $c = 0; $x =~ /A/g; while ($x =~ /\GB/g) { ++$c; last if $c > 1000; } say $c; ' 1