in reply to Help w passing array by ref

You are passing the array to makeSQL as a ref here:

my $sql = makeSql(\@xpid);
However here you make an error:
sub makeSql { my @xpid = shift; # <----------- error my $return; # try: my $xpid = shift my $i = 0; ^ foreach my $item (@xpid) { # <-- error $return .= $xpid[$i]; # <-- error # try: foreach my $item (@$xpid) ^ # try: $return .= $$xpid[$i]; ^
The reference the is passed to the function should be stored in a scalar. When it then needs to be used as an array you dereference it with @$xpid and then again with $return .= $$xpid[$i];.

--tidiness is the memory loss of environmental mnemonics