Just in case you need offsets as well, here's a solution for that.
use strict;
use warnings;
use feature qw{ say };
my $string
= q{AAATTTAGTTCTTAAGGCTGACATCGGTTTACGTCAGCGTTACCCCCCAAGTTATTGGGGACT
+TT};
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;
The output, sorted ascending offset within ascending letter within descending length.
Found CCCCCC, length 6 at offset 42
Found GGGG, length 4 at offset 56
Found AAA, length 3 at offset 0
Found TTT, length 3 at offset 3
Found TTT, length 3 at offset 27
Found TTT, length 3 at offset 62
Found AA, length 2 at offset 13
Found AA, length 2 at offset 48
Found GG, length 2 at offset 15
Found GG, length 2 at offset 25
Found TT, length 2 at offset 8
Found TT, length 2 at offset 11
Found TT, length 2 at offset 39
Found TT, length 2 at offset 51
Found TT, length 2 at offset 54
I hope this is helpful.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.