sub csv_split { local $_ = shift // return; my $is_quoted; my $count = my @array; while ( s/(.)// ) { if ($1 eq ',' and not $is_quoted) { $count++; } elsif ($1 eq q/"/ and not ( $is_quoted and s/^\"// )) { $is_quoted = !$is_quoted; } else { $array[$count] .= $1; } } return if $is_quoted; wantarray ? @array : \@array; }