foreach $word ( @wordlist ) { .... } #### use strict; my @nocapslist = qw/ in and the for it but to with about or nor because as that /; sub make_a_title { my $string = shift; $string =~ s/^\s+//; my @wordlist = split (/\s+/, ucfirst( $string ) ); join( ' ', map{ my $word = $_; ## not quite efficient like Ovid's;-) (grep{ $_ eq $word } @nocapslist) ? $word : ucfirst( $word ); } @wordlist ); } my $str = "this is a sentence, for You and For me Blah Blah blah"; print make_a_title( $str );