use strict; use warnings; while () { if ( /^StartTr1/ .. /^oflTr1/ ) { print unless (/^StartTr1/) or (/^oflTr1/); } } __DATA__ StartTr1 sample 1 sample 1 sample 1 sample 1 SAMPLE 1 oflTr1 nothing nothing nothing StartTr1 sample 2 sample 2 sample 2 sample 2 sample 2 last line before sample 2 oflTr1 junk junk junk