use strict; sub main{ my $text = qq{a,b,"hey, you","str1, str2, str3",end}; print "Input: $text\n\n"; # Split the delimiters my @values = split( /(?:\,|(\".*?\"))/ , $text); # Remove the created blanks @values = grep{$_ ne ''} @values; # Output foreach (0..$#values){ print "$_: $values[$_] \n"; } } main();