(my $f=shift)=~s/(^| )(\w)/$1\U$2/g; # Doing it with lookbehind gets a little ugly: # s/(?:(?<=^)|(?<= ))(\w)/\U$1/g; $f;