in reply to Refining my Program

On Unix:
perl -pi.bak -e 's/(.*),(.*)/$2 $1/' test.txt
Windows uses " instead of '.

Beyond that, have an indentation style, check $! on open, and it usually winds up being a bad idea to edit files in place - leave the original and write a copy. (Or at least keep a backup as I did above.)