http://qs1969.pair.com?node_id=681931


in reply to Recommendations for parsing invalid CSV

You could use look-behind (?<= ) and look-ahead (?= ) expressions to look only for quotes which are not beside a comma or at end and start of the line:
s/(?<=.)(?<!,)"(?!,|$)/\\"/g A simple test in the command line brings me:
user@machine$ perl -pe 's/(?<=.)(?<!,)"(?!,|$)/\\"/g' "call from "friend"","call from "friend"","call from "friend"" "call from \"friend\"","call from \"friend\"","call from \"friend\""
The 2nd line is input, the 3rd output.

Looks good for me. Some special cases with escaped commas inside the strings might not match correctly. You should check this.