It really depends on exactly what you're doing with your data -- but hey, you're headed the right way with your last question! Don't guess, benchmark.
Perl provides the Benchmark module for exactly this kind of thing, and using it is really pretty straightforward. Here's a little sample code to get started with:
#!/usr/bin/perl
use strict;
use warnings;
use Benchmark qw(cmpthese);
my $dna;
$dna .= [qw(G A T C)]->[rand 4] for 1 .. 100;
sub frequency_substr {
my $length = length $dna;
my %hist;
for my $pos (0 .. $length) {
$hist{$pos}{substr $dna, $pos, 1} ++;
}
\%hist;
}
sub frequency_split {
my %hist;
my $pos = 0;
for my $char (split //, $dna) {
$hist{$pos ++}{$char} ++;
}
\%hist;
}
sub frequency_regmatch {
my %hist;
while ($dna =~ /(.)/g) {
$hist{pos($dna)}{$1} ++;
}
\%hist;
}
cmpthese(-5, # Run each for at least 5 seconds
{
substr => \&frequency_substr,
split => \&frequency_split,
regex => \&frequency_regmatch
}
);
And a sample result:
Rate regex split substr
regex 6254/s -- -26% -32%
split 8421/s 35% -- -9%
substr 9240/s 48% 10% --
Turns out substr is surprisingly fast. :)