knoppix@Microknoppix:~$ perl -Mstrict -MData::Dumper -wE ' > my $str = q{ATCGGCGCCTAT}; > my @words = unpack q{(a3)*}, $str; > my %counts; > > foreach my $word ( @words ) > { > my $posn; > $counts{ q{position } . ++ $posn }->{ $1 } ++ > while $word =~ m{(.)}g; > } > > print Data::Dumper->Dumpxs( [ \ %counts ], [ qw{ *counts } ] );' %counts = ( 'position 1' => { 'A' => 1, 'T' => 1, 'G' => 2 }, 'position 3' => { 'T' => 1, 'C' => 3 }, 'position 2' => { 'A' => 1, 'T' => 1, 'C' => 1, 'G' => 1 } ); knoppix@Microknoppix:~$