Is this what you were looking for? The longest matching DNA string? You can save the max length found below to get your result.

Answer:

Found match of length (102) at position(506, 0):

AAATTGGTGTATATGAAAGACCTCGACGCTATTTAGAAAGAGAGAGCAATATTTCAAGAATGCATGCGTCAATTTTACGCAGACTATCTTTCTAGGGTTAAT
AAATTGGTGTATATGAAAGACCTCGACGCTATTTAGAAAGAGAGAGCAATATTTCAAGAATGCATGCGTCAATTTTACGCAGACTATCTTTCTAGGGTTAAA

my $i=-1; while(++$i < length($reference_str)) { my $j=-1; while(++$j < length($small_str)) { my $length = 9; my $match=undef; while ( $i+$length < length($reference_str) and $j+$length < length($small_str) and compareSnippet($i, $j, ++$length) ) { $match++; } if ( $match) { $length--; print "Found match of length ($length) at position($i, $j): +\n"; print substr($reference_str, $i, $length) . "\n"; print substr($small_str, $j, $length). "\n"; $i+= $length; $j+= $length; next; } } } sub compareSnippet { my ( $pos_i, $pos_j, $length) = @_; my $ref = substr($reference_str, $pos_i, $length); my @ref_arr = sp +lit('', $ref); my $small = substr($small_str, $pos_j, $length); my @small_arr = sp +lit('', $small); return undef if length($ref) < $length or length($small) < $length; return equal(\@ref_arr, \@small_arr); } sub equal { my ($first, $second) = @_; my $mismatch=0; foreach my $i (0..(@$first-1)) { $mismatch++ if $first->[$i] ne $second->[$i]; return undef if $mismatch > 1; } # print "Woo! (@$first, @$second)\n" if $mismatch == 0; return 1; }

In reply to Re^3: How do you match a stretch of at least N characters by paisani
in thread How do you match a stretch of at least N characters by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.