in reply to I still can't get only the necessary lines from the file.

I think I understand now
you want the text between the first Start and first Exit
you can throw in a last to exit the loop when matching Exit
open (DATA,"<xxx.txt") || die "Can't open xxx.txt: $!\n"; while(<DATA>) { if (/Start context/ .. /\* Exit context \*/) { print unless /(Start context|\* Exit context \*)/; last if /\* Exit context \*/; } }