http://qs321.pair.com?node_id=1160598


in reply to Replace commas with spaces between quotes, parsing CSV

Here's mine, a different approach, based on the idea "replace what you want to keep by itself":
s/(,)|(".*?")/ $1 || $2 =~ s(,)( )gr /ge;
This requires a "fairly recent" perl, though I'm unsure exactly when s///r was introduced.

For older (and for newer) perls, you can use the slightly more verbose:

s/(,)|(".*?")/ $1 || do { (my $s = $2) =~ s(,)( )g; $s } /ge;