@fookeys = grep $HoH{$_}{foo} eq 'bar2', keys %HoH; print "@fookeys\n"; # Only `2' is there.