sub parse_csv { my $text = shift; # record containing cs values my @new = (); push(@new, $+) while $text =~m{ #the first part groups the phrase inside the quotes #see expl of this pattern in MRE "([^\"\\]*(?:\\.[^\"\\]*)*)",? | ([^,]+),? | , }gx; push(@new,undef) if substr($text, -1,1) eq ','; return @new; #list of values that were comma separated } or standard module use Text::ParseWords; sub parse_csv { return quoteword(",",0,$_[0]); }