http://www.perlmonks.org?node_id=731489


in reply to Using grep to pick out lines in a text file

This could be a useful if you are wondering the solution with minimal number of lines.
open( INPUTFILE, "<WordNet.txt" ) or die "$!"; open( OUTPUTFILE, ">>WordNetTest2.txt" ) or die "$!"; grep { /adj:/ and print OUTPUTFILE $prev,$_;$prev=$_ } (<INPUTFILE>) +;