my @keys = qw( a b c d ); my %h = ( b => 'b' ); my @found = grep {defined} (@h{@keys})[0..@keys]; print Dumper \%h; print Dumper \@found