in reply to perl substitution difficulty
Adding just a thought to the solutions already given.
The output .csv file might be in error/unusable if some fields written to it (the actual message part) can contain commas too. No problem if you know for sure that that cannot happen, but otherwise, later problems are lurking.
Take care.