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