in reply to Reformat Text File

I'm slightly bored today, and I've made a few assumptions about the format of your text.
1 while s/^(\w+),(.*)\n\1,(\w+)$/$1,$2,$3/m;