my $removing = 0; while (<>) { if (/^MYTAG1/) { $removing = 1; } elsif (/^MYTAG2/) { $removing = 0; } print unless $removing; }