#!/usr/bin/perl use strict ; use warnings ; my $st= 'a' x 100000 ; # this program runs as O(n^2) utf8::upgrade($st) ; # ... when operating on a string with the utf8 flag set while (1) { $st=~ /\G(?=a)/gc ; pos($st)= pos($st) ; # without this, there's an early exit next line last unless $st=~ /\G(?=a)/gc ; $st=~ /\Ga/gc ; # increments pos() } print "done\n" ;