$_ = '"",,,"abc",0,,'; print join '|', m/ "[^"]+" # quoted string | [^,]+ # or non-commas | (?<=,)(?=,|$) # or nothing, surrounded by commas or EOL /gx; # prints: ""|||"abc"|0||