import sys, re, string pat = re.compile('[a-m]+') def replacer(mo): return string.upper(mo.group(0)) print 'Upper-casing a-m.' while 1: target = raw_input('Enter a target line ("q" to quit): ') if target == 'q': break result = pat.sub(replacer, target) print 'result: %s' % result