#!/usr/local/bin/perl # repl.pl use strict; open INPUT, "output.txt" or die "Hcrelb: $!\n"; my $replace_string="Hi there.\n"; my $flag=0; my %markers=("BEGIN" => "", "END" => "", ); while () { if ($flag) { next unless /$markers{END}/; $flag=0; print OUTPUT $replace_string; } print OUTPUT; $flag=1 if /$markers{BEGIN}/; } __END__ > cat input.txt But now I know that twenty centuries of stony sleep were vexed to nightmare by a rocking cradle. And what rough beast, it's hour come round at last, slouches towards Betlehem to be born? A poem W. B. Yeats > repl.pl ; cat output.txt But now I know that twenty centuries of stony sleep were vexed to nightmare by a rocking cradle. And what rough beast, it's hour come round at last, slouches towards Betlehem to be born? Hi there. W. B. Yeats