$s = 'a,b,"hey, you","str1, str2, str3",end'; @fields = $s =~ /("[^"]+"|[^,]+)(?:,|$)/g; # Use +, not *, or you get a blank element print "$_\n" for @fields;