my %sth; foreach my $tab (@checklists) { # BTW, this SQL may be better written: # select 1 from $tab where word = ? # if all you're testing for is existence... $sth{$tab} = $dbh->prepare("SELECT word from $tab where word = ?"); } # later... foreach my $tab (@checklists) { $sth{$tab}->execute($word); my $ret = $sth{$tab}->fetchrow_hashref(); }