print capitalize("red hot chili peppers\nby the way\n"); { my %exception; sub capitalize { my $string = shift; %exception = map{$_=>1}qw(and or the a an etc) unless keys %exception; $string =~ s/(\w+)/$exception{$1}?$1:ucfirst($1)/ge; return $string; } }