perlfaq nodetype
faq_monk
<P>
To make the first letter of each word upper case:
<P>
<PRE> $line =~ s/\b(\w)/\U$1/g;
</PRE>
<P>
This has the strange effect of turning ``<CODE>don't do it</CODE>'' into ``<CODE>Don'T
Do It</CODE>''. Sometimes you might want this, instead (Suggested by Brian Foy):
<P>
<PRE> $string =~ s/ (
(^\w) #at the beginning of the line
| # or
(\s\w) #preceded by whitespace
)
/\U$1/xg;
$string =~ /([\w']+)/\u\L$1/g;
</PRE>
<P>
To make the whole line upper case:
<P>
<PRE> $line = uc($line);
</PRE>
<P>
To force each word to be lower case, with the first letter upper case:
<P>
<PRE> $line =~ s/(\w+)/\u\L$1/g;
</PRE>
<P>
You can (and probably should) enable locale awareness of those characters
by placing a <CODE>use locale</CODE> pragma in your program. See [perlman:perllocale|the perllocale manpage] for endless details on locales.
<P>