Thanks to all who helped me with this.

All suggested solutions worked perfectly (even if I did claim I was 
still getting incorrect line lengths).  It was a combination of embedded 
commas (the problem I'd asked about) and embedded SQL terminations ";" 
inside comments.

My original code did

input.each(";") do |line| ...

now I'm using the more robust

input.each(");") do |line|

and I avoid these nasty ";" embedded in comments

Again all help was much appreciated - FYI I'm using the first solution 
offered to remove the commas.

Kev