Your question is not easy to understand. Would it be possible to provide:
- A sample input file, just a couple of lines,
- the desired output file, and
- some more ideas what you want to match and replace?
Also, it seems, as your example grows more complex, you should be using Text::CSV, which allows you to first split your line properly along the commata, and then to split any entry along commata.