http://www.perlmonks.org?node_id=887866


in reply to List manipulation headache

Depending on your input data, this should be pretty easy to do with a regex.
For instance, if your input file looks exactly like your snippet above, you could probably get away with just putting these two lines in a while loop:
s/ wap/, /g; s/, / wap/; # change back the first occurrence on each line