my @combined = (); my ($col1, $col2, $col3, $col4) = ''; while (@array1) { $col1 = shift @array1; chomp $col1; $col1=~s/,/\,/g; #escape commas $col2 = shift @array2; chomp $col2; $col2=~s/,/\,/g; $col3 = shift @array3; chomp $col3; $col3=~s/,/\,/g; $col4 = shift @array4; chomp $col4; $col4=~s/,/\,/g; push @combined, "$col1,$col2,$col3,$col4\n"; } open OUTPUT, ">$target_file" or die "Cannot open target file! $! \n\n"; print OUTPUT @combined; close OUTPUT;