while (<>){ if (/BEGIN PATTERN/ .. /END PATTERN/){ #line falls between BEGIN and END in the text. } }