my $sth3 = $dbh->prepare("select name,value from A where in (".join(",",@var1).")"); - @var1 contains the 5 values $sth3->execute(@var1); while (my @row = $sth3->fetchrow_array) { print join(", ", @row), "\n"; }