$punc = "?!."; ucfirst($string); $string =~ s#([$punc][^a-z]*[a-z])#uc($1)#eg; ## or $string =~ s#([$punc]\s*[a-z]#uc($1)#eg;