my @ids_to_match = ( ... ); my $query = "SELECT somedata from table WHERE id IN (" . join(",", map {"?"} @ids_to_match ) .")"; my $sth = $dbh->prepare($query); $sth->execute(@ids_to_match);