sub somefunction { my ($href, $key) = @_; my %counts; $_->{$key} && ++$counts{$_->{$key}} for values %$href; return %counts; }