I can't reproduce your problem (on the W7 machine available right now).
C:\>perl -p -w -e "s/(\w+)/\u\L$1/;" # quoting changed from OP to obl
+ige M$
foo
Foo
....
Beyond that, and even though none of this is really on point:
- It's not, as your title has it, "the same script." The first version provides an explicit means, <>, of getting a "word" into the "script" while the second uses one version of a 'wrap in a loop' feature ,-p. (BTW, you can concatenate the options as -pwe ... or in 5.14 -- perhaps earlier -- as -pwE to enable features like say. If you do so, the -w becomes unnecessary, since recent versions of Perl -- when executed with features enabled -- automatically invoke use strict; use warnings;.)
- The \L in the substitution can be omitted because you use \u which uppercases the first letter only. An upper case \U would say 'uppercase the rest of the word' (and gets Perl to squawk if used together with <c>\L<c>
Updated: typo fixed