while(){ @words=split; for(@words){ /(?:(the|or|and)|\w+) #Capture "the|or|and" (?(1) #Switch on captured value (?{print"$_ "}) #If there is a captured value just print |(?{print "\u\L$_ "}))#If not convert first char uppercase /x; } } __DATA__ red hot chili peppers, by the way