#!/usr/bin/perl -w use strict; while(){ s/\b(\w+(?:['-]\w+)*)\b/\L\u$1/g; s/(\w+(?:['-]\w+)*[\W\s]*)$/\U$1/; print; } __DATA__ tHis IS just one exAMPle, note: some STRINGS haVe apOStrophEs or hyPHens, and perhaps faulty punctuation or trailing elipsis ... doN't SETTLE for over-THE-counter sOLutions! !! including this one.