#!/usr/bin/perl use strict; use warnings; while () { my $i = (/\*\*Temp/ .. /\*\*End/); print unless ($i && $i > 1 && substr($i, -2) ne 'E0'); } __DATA__ first second **Temp** fdvfd fgd dfgd dfgd **End Temp ** this is test dffdgd this is test dffdgd #### first second **Temp** **End Temp ** this is test dffdgd this is test dffdgd