my %outputhash; $outputhash{$_->{department}}++ for grep { $_->{department} } values %testhash;