my @data = resolve_comma_delimited_file_line($CSVFILE, $this_line); # This subroutine accepts a filehandle and a line read from that filehandle as arguments given in that order. # If necessary it will modify the line that was passed to it (as if passed by reference) to resolve it, and return an array of the split data. sub resolve_comma_delimited_file_line { my $fh = $_[0]; chomp($_[1]); # $_[1] being the read line passed in to this subroutine that is to be modified if necessary (as if passed by reference) my @data = split /,/, $_[1], -1; my $last_index = $#data; for (my $field_index=0; $field_index<$last_index; $field_index++) { if (($data[$field_index] =~ tr/"//) % 2 == 1) { splice @data, $field_index, 2, "$data[$field_index] $data[$field_index+1]"; $_[1] = join ",", @data; $last_index--; $field_index--; } } if (($data[$last_index] =~ tr/"//) % 2 == 1) { $_[1] .= " " . <$fh>; @data = &resolve_comma_delimited_file_line; } return @data; }