my $list = join ",", @a1; foreach(@b1){ $sql = "select x from y where v = $_ and z in($list)"; print $sql . "\n"; }