use warnings; use strict; my %hash = ( 'A2M' => [ 'C972Y', 'A423W' ], 'A4GALT' => [ 'W261X', 'P251L', 'P251S', 'A219V' ] ); for my $k (sort keys %hash) { print "Current key is\t" . $k . "\n"; my $totalcount = @{ $hash{$k} }; my $xcount = grep { /X/ } @{ $hash{$k} }; print $k . "\t" . $totalcount . "\t" . $xcount . "\n"; } __END__ Current key is A2M A2M 2 0 Current key is A4GALT A4GALT 4 1