#!/usr/bin/perl -w use strict; while () { s/(.*ing)((?!bob|fred|bill(?!ess))\w+?)(more|less)/$1HIT$3/; print $_; } __DATA__ somestringbobmoremore somestringfredmoremore somestringbillmoremore somestringtedmore somestringbilless #### somestringbobmoremore somestringfredmoremore somestringbillmoremore somestringHITmore somestringHITless