use strict; use warnings; use feature qw{ say }; my $string = q{AAATTTAGTTCTTAAGGCTGACATCGGTTTACGTCAGCGTTACCCCCCAAGTTATTGGGGACTTT}; my @matches; push @matches, [ length $1, $1, $-[ 0 ] ] while $string =~ m{(([ACGT])\2+)}g; say qq{Found $_->[ 1 ], length $_->[ 0 ] at offset $_->[ 2 ]} for sort { $b->[ 0 ] <=> $a->[ 0 ] || $a->[ 1 ] cmp $b->[ 1 ] || $a->[ 2 ] <=> $b->[ 2 ] } @matches;