in reply to Capitalize only the first letter of the first word in a string
ucfirst upper cases the first letter and leaves the remaining letters unchanged so you need to lowercase the string first. That will give you the answer you claim to want, but not the result you indicate in your code. For that you need something more like:
use strict; use warnings; for my $str ('BELLMONT NY', 'NEW YORK NY') { my @words = split /\s+/, $str; $_ = ucfirst lc for grep {/\w{3,}/} @words; print "$str: ", join (' ', @words), "\n"; }
Prints:
BELLMONT NY: Bellmont NY NEW YORK NY: New York NY
|
|---|