my @terms = ('recent', 'biology'); my @matches = keys %{ $table{ (shift @terms) } }; foreach my $term (@terms) { @matches = grep { exists $table{$term}{$_} } @matches; } printf "Found %05d matches!\n", scalar @matches;