use warnings; use strict; while () { s/(\w+)/ucfirst lc $1/e; print; } __DATA__ BELLMONT NY NEW YORK NY #### Bellmont NY New YORK NY