my $query = 'apple'; my $sql = qq{ SELECT COUNT(*) FROM table1 WHERE name=? UNION SELECT COUNT(*) FROM table2 WHERE name=? }; my $sth->execute($sql, $query, $query) my $rows = $sth->fetchall_arrayref(); #table1 apple apple orange pear #table2 pear apple orange orange