#!/usr/bin/perl -w use strict; $/ = undef; while(){ s{(BEGTITLE.*?ENDTITLE)} { my $rec = $1; $rec =~ s/wirey/smooth/ig; $rec; }gse; print; } __DATA__ BEGTITLE The wirey life of a wirey haired dog ENDTITLE BEGTXT blah blah blah ENDTXT BEGTITLE Grooming dogs ENDTITLE BEGTXT Grooming a wirey haired dog is ... ENDTXT BEGTITLE Last wirey haired dog story ENDTITLE BEGTXT we don't need no steenkin' wirey haired dogs here ENDTXT BEGPUB Wirey Haired Dogs Life ENDPUB BEGTITLE My dog has wirey hair ENDTITLE BEGTXT My wirey hair dog...blah, blah. ENDTXT BEGTITLE My dog still has wirey hair ENDTITLE BEGTXT more wirey haired dog stuff ENDTXT