my $a= ' I have SOME WORDS in full CAPS '; $a =~ s{\b([A-Z]{4,})\b/}{ucfirst(lc($1))}eg; print $a, "\n"; # wanted: I have Some Words in full Caps