in reply to searching data lines between keywords

and a less fancy aproach:
OUT: while(<>) { next unless /keyword2/; while(<>) { last OUT if /keyword4/; process_line($_); } }