in reply to How to grep for values & see the keys?

Using 'map' as a 'grep' :)

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11143876 use warnings; my %hash; @hash{1..26} = 'a' .. 'z'; my %want = map { $hash{$_} =~ /c|x/ ? ($_, $hash{$_}) : () } keys %has +h; use Data::Dump 'dd'; dd \%want;

Outputs:

{ 3 => "c", 24 => "x" }