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