foreach my $string ( 'i am the very model of a modern major-general.', 'this is one sentence. this is two.', 'foo bar', 'outside parens (inside them)', 'outside brackets [inside them], now braces {inside}', ) { (my $two_capture = $string) =~ s/ (^|[-\s(]) (\w) / $1 . uc $2 /egx; (my $boundary = $string) =~ s/ \b (\w) / uc $1 /egx; (my $alternation = $string) =~ s/ (-|\s|^|\() (. ) / $1 . uc $2 /egx; print( "string: $string\n", "two_capture: $two_capture\n", "boundary: $boundary\n", "alternation: $alternation\n", "\n" ); }