The Text::CSV_XS module shown above would probably be your most-reliable solution. To elaborate, you would read each line of data, use this module to separate the line into an array of values, then combine the strings as desired ... perhaps, into a new array. Then, use the same module to construct a new line of CSV-formatted data from the array, which you write line-by-line to a new file. (Perhaps, a temporary file.) Notice that this technique purposely does not modify the original input file, allowing the program to be safely re-run while you debug it. The module does all the dirty work (which can be tricky) of decoding and re-encoding the CSV data. You simply concern yourself with the values.