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