use strict; use warnings; my %counts; my $max = 0; while () { chomp; my $code = (split)[-1]; my $i = 0; for my $c (split //, $code) { $counts{$c}{$i++}++; } $max = $i if $i > $max; } $max--; for my $c (keys %counts) { print "$c "; for my $i (0 .. $max) { if (exists $counts{$c}{$i}) { print " $counts{$c}{$i}"; } else { print ' 0'; } } print "\n"; } __DATA__ fred ATGTTGTAT fred1 ATCTTATAT fred2 ATCTTATAT #### A 3 0 0 0 0 2 0 3 0 T 0 3 0 3 3 0 3 0 3 C 0 0 2 0 0 0 0 0 0 G 0 0 1 0 0 1 0 0 0