$a = "thIs SeNTenCE iS AlL meSSEd Up!"; $b = join(" ", map ucfirst(lc($_)), split(/\s+/, $a)); print "Before: $a\n"; print "After: $b\n";