use FreezeThaw qw(cmpStr); sub f { my ($h) = @_; return grep cmpStr(@{$h->{$_}}{qw/C O/}), keys %$h; } #### use FreezeThaw 'cmpStr';sub f{my($h)=@_;grep{!exists$$h{$_}{O}||cmpStr@{$$h{$_}}{C=>'O'}}keys%$h} #### # 1 2 3 4 5 #23456789012345678901234 56789012345678901234567890 use FreezeThaw 'cmpStr';sub f{grep{!exists$$_{O}||cmpStr # 6 7 #2345678901234567890123456 @$_{C=>'O'}}values%{$_[0]}}