my @id=(1,2,3,4); my $question_mark_string = join(',', ('?') x scalar(@id) ); # ?,?,?,? my $sth = $dbh1->prepare("SELECT name FROM table where id in ( $question_mark_string )") or die "Couldn't prepare statement: " . $dbh1->errstr; $sth->execute(@id)