in reply to Re^5: How to match more than 32766 times in regex?
in thread How to match more than 32766 times in regex?

Hm, I don't know what it has to do with alternating substrings, but here's another version of your program :)
use strict; use warnings; use List::Util 'reduce'; for (1 .. 25) { my $digits = join '', map {int rand 2} 1 .. 100_000; my $substr = longest($digits); printf "%02d: At position (%6d), length (%6d) => $substr\n", $_, index($digits, $substr), length($substr); } sub longest { return reduce { length($a) > length($b) ? $a : $b; } split /(?<=0)(?=1)|(?<=1)(?=0)/, $_[0]; }
Works a bit faster, too.