in reply to Question about speeding a regexp count

You can use a regexp, but you ought to make it work in one pass. It's a little tricky, but it benches favorably with ikegami's solution.
sub roy { my %count; while ($seq =~ /(?=(((.).).))/g) { ++$count{$1}; ++$count{$2}; ++$count{$3}; } # pick up the last two chars $seq =~ /((.)(.))$/; ++$count{$1}; ++$count{$2}; ++$count{$3}; 1; }
$seq should be at least 3 chars long.

Caution: Contents may have been coded under pressure.