use Tie::DBI; use List::Compare; tie %h,'Tie::DBI',{db => 'mysql:db', table => 'table', key => 'k', user => 'root', password => 'rootpass', CLOBBER => 1}; %day = ('the' => '1', 'tuesday' => '2', 'wednesday' => '3'); $lc = List::Compare->new([keys %day],[keys %h]); @intersections = $lc->get_intersection; foreach $intersection (@intersections) { print $intersection, "\n"; print $h{$intersection}{value}, "\n"; } exit;