sub csv_split { local $_ = shift || return undef; my @array = (); my $count = my $quoted = 0; while ( /([^,"]+|[,"])/g ) { if ($1 eq ',' and !$quoted) { $count++; } elsif ($1 eq '"') { $quoted = !$quoted; } else { $array[$count] .= $1 } } @array; }