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"; }