use warnings; use strict; while () { s/(\w+)/$1,/g; print; } __DATA__ This is a word. Here is another sentence.