Assuming they don't also contain commas and always start and end with a non-space ... s/^\s*(\S(?:[^,]*\S)?)\s*,\s+(\S).*$/${2}${1}/;Update: Fix for ysth's objections.
My criteria for good software:
Does it work?
Can someone else come in, make a change, and be reasonably certain no bugs were introduced?