# Retrieve all IDS were first number is 2 my @ids = grep { $hoh->{$_}->{first_number} == 2 } keys $hoh;