sub somefunction { my ($hash, $key) = @_; my %outputhash; $outputhash{$_->{$key}}++ for values %$hash; %outputhash; }