#!/usr/bin/perl -w use strict; $/ = undef; my $text = ; $text =~ s/(BEGTITLE.*?)wirey(.*?ENDTITLE)/$1smooth$2/gsi; print $text; __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 # output is: BEGTITLE The smooth life of a wirey haired dog ENDTITLE BEGTXT blah blah blah ENDTXT BEGTITLE Grooming dogs ENDTITLE BEGTXT Grooming a smooth haired dog is ... ENDTXT BEGTITLE Last wirey haired dog story ENDTITLE BEGTXT we don't need no steenkin' wirey haired dogs here ENDTXT