my %table = ( recent => {'c:/autoexec.bat'=>undef, 'c:/frog.jpg'=>undef}, text => {'c:/autoexec.bat'=>undef, 'c:/classnotes.txt'=>undef}, biology => {'c:/classnotes.txt'=>undef, 'c:/frog.jpg'=>undef}, ); #### 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;