in reply to
How to print the lines immediately above and below a matching line?
TMTOWTDI answer. :-)
Instead of reading the file line by line as suggested in other answers above, you could also read the entire file into a scalar and use a multi line regexp to do it. Look up use of the /m option on regexp matching.
Any Monk who wishes to extend this thread with a complete answer using this method is more than welcome to do so (I'm a bit short of time)
A Monk aims to give answers to those who have none, and to learn from those who know more.