in reply to Equivalent of Linux Grep Command
That's a reasonable start to an implementation.
Any solution I can think of involve scanning the file and maintaining @before and @after buffers as you go.
Perl isn't really intended to provide one liners for every common unix command, and grep itself is a tool not a programming language, any implementation of grep in C is considerably more than one 80 character line of code.
There is a program called prep on CPAN, which is a pure perl implementation of grep. The source to that program may provide inspiration.