## untested "idea" code ## package TwoWayHash; use overload '%{}' => \&as_hash; sub new { my $self = shift; my $hashref = shift; my %struct = ( 'data' => $hashref ); bless \%struct, $self; } sub as_hash { my $self = shift; # this will only work for simple hashes, really my $temp = reverse $self->{data}; return $temp{shift}; } #### use TwoWayHash; my %a = get_results_from_query; # assume this populates %a; # then, when you need $b{$a}: { my $b = TwoWayHash->(\%a); print "I need ",$$b{'item'}; ## finds key where $a{key} eq 'item' } #### print "I need", rv_lookup('item',\%a);