# Itterate over the contents of the @NewItem list # For each item in the list, set $item to the value # (equivalent to $NewItem[$z] in your code) foreach my $item (@NewItem) { # And add this value in like you did before. $SQLString = $SQLString . $item . "\',\'"; }