# Lets create a hash that has some similar keys and some unsimilar keys %h1 = ( cat => 1, dog=> 2, catalog => 3, doggerel => 4 } x \%h1 0 HASH(0x7f9cb41aaad0) 'cat' => 1 'catalog' => 3 'dog' => 2 'doggerel' => 4 # See ALL the keys ... x keys %h1 0 'cat' 1 'doggerel' 2 'catalog' 3 'dog' # grep allows us to filter that list x grep { /cat/ } keys %h1 0 'cat' 1 'catalog' # You access a single hash element with $h{$key} # You can access multiple elements, called a slice, # using an array or list of keys. In this case you have to put # a '@' sigil in front, rather than a '$', to indicate #you're expecting multiple values x @h1{grep { /cat/ } keys %h1} 0 1 1 3 # So 'cat' -like keys have the values, '1' and '3'. # If you wanted to assign those to the keys in # another hash, I would save the set of keys in a temp: @a = grep { /cat/ } keys %h1 @b{@a} = @h1{@a} DB<14> x \%b 0 HASH(0x7f9cb41bd0e8) 'cat' => 1 'catalog' => 3