my $re = qr/(.)\1*/; @matches = $string =~ m/($re)/g; print "@matches\n"; # x x x x 5 5 5 5 6 6 x x x x @matches = $string =~ m/((??{$re}))/g; print "@matches\n"; # xx 55 6 xx