Commander Salamander,
This trades memory for speed but still ran fine on my 256MB machine with a 600_000 byte DNA strand.
my $dna = join '', map { chomp; $_ } <DATA>; my $template = ('AXA2X2A3X2' x (length($dna) - 2)) . 'AXA2XA'; my %count; $count{$_}++ for unpack $template, $dna; print "$_\t$count{$_}\n" for keys %count; __DATA__ AAAAAAAACAAGAATACACAACCACGACTAGAGAAGCAGGAGTATATAATCATGATTCCACAACACCAGC +ATCCCCACCCCCGCCTCGCGACGCCGGCGT CTCTACTCCTGCTTGGAGAAGACGAGGATGCGCAGCCGCGGCTGGGGAGGCGGGGGTGTGTAGTCGTGGT +TTTATAATACTAGTATTCTCATCCTCGTCT TGTGATGCTGGTGTTTTTATTCTTGTTTAACACAACCACTAGAGCAGTATATAATCCCACACCAGCCCCC +CCTCGCGACGGCGTCTCTACTCCTGGGAGA CGAGGATGCGCAGCGGCTGGGGAGGGGTGTAGTCTTATACTAGTATTCTCCTCGTCTTGTGATGCTGGAC +TGGGGTCGATCGTCGAAATCGGCTAGCTAA AAAAAAACAAGAATACACAACCACGACTAGAGAAGCAGGAGTATATAATCATGATTCCACAACACCAGCA +TCCCCACCCCCGCCTCGCGACGCCGGCGTC TCTACTCCTGCTTGGAGAAGACGAGGATGCGCAGCCGCGGCTGGGGAGGCGGGGGTGTGTAGTCGTGGTT +TTATAATACTAGTATTCTCATCCTCGTCTT GTGATGCTGGTGTTTTTATTCTTGTTTAACACAACCACTAGAGCAGTATATAATCCCACACCAGCCCCCC +CTCGCGACGGCGTCTCTACTCCTGGGAGAC
If memory becomes an issue, you could walk the length of the string using substr or unpack. It will require keeping track of your position in the string but both functions provide a means for starting "inside" the string.

Cheers - L~R

Update: After testing the memory consumption, I updated the post to reflect that it may be realistic to use this approach


In reply to Re: Question about speeding a regexp count by Limbic~Region
in thread Question about speeding a regexp count by Commander Salamander

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.