use strict; use Data::Dumper; my $string =' aaaa bbbbccccccccbbbb aaaabbbbbcdddddddddddddddddddd'; my @bah; my $old_pos = 0; while ($string =~ /((.)\2*)/g) { push @bah, [$2,$old_pos,length($1)]; $old_pos = pos($string); } print Dumper(\@bah);