There are modules for this. What about "MacDonald" and other such names? See modules starting with
Lingua::EN. (e.g. NameCase, NameParse (Although it must be said that NameParse IS rather slow, so its not very good for frequent processing of large datasets))
The simple solution, though, as you ask for it, is:
my $str = "ABC DEF";
$str =~ s/(\w+)/\u\L$1/g;