my $best = ""; $best = $1 while $string =~ /((.)\2*)(*SKIP)(?(?{length $^N <= length $best})(*FAIL))/g; print "best: $best\n"