$ perl -wle'print for "aabbaab" =~ /((.)\2+)/sg;' aa a bb b aa a #### $ perl -wle'print $1 while "aabbaab" =~ /((.)\2+)/sg;' aa bb aa