sub parse_csv { my $text = shift; ## record containing comma-separated values my @new = (); push(@new, $+) while $text =~ m{ ## the first part groups the phrase inside the quotes "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push(@new, undef) if substr($text, -1,1) eq ','; return @new; ## list of values that were comma-spearated } ## Use like this: @goodlist = parse_csv($csvlist);