my @array = (10,15,20); my $where_list = ''; foreach my $index (0..$#array) { $where_list .= ($index) ? "and\n" : "where\n"; $where_list .= " company_id='$array[$index]'\n"; } $sql = <