while () { if (/^FH$/ .. /^FT$/) { # $_ is a line within FH and FT lines # including the delimiting lines } if (/^BH$/ ... /^BH$|^FT$/) { # $_ is a line between BH lines, or between # a BH and FT line }