in reply to Simple SQL like thingy?

Your question is a little oddly put, so I can't be sure I'm answering what you asked. If you want to do a database-like selection of keys from a hash, grep is probably the best way to support the logic:

#assumes %the_hash{'this_id'} = { key1=>'quux', key4=>12 } and so on my @selected_id_keys = grep { ( exists $the_hash{$_}{'key1'} and $the_hash{$_}{'key1'} eq 'foo') and ( exists $the_hash{$_}{'key2'} and $the_hash{$_}{'key2'} eq 'bar') or ( exists $the_hash{$_}{'key4'} and $the_hash{$_}{'key4'} < 10) } keys %the_hash;
You want to check existance of the key before testing values, so as to avoid autovivifying a key that's not present. The parens in the logic are for human eyes, they do not affect evaluation in this case.

After Compline,
Zaxo