use strict; use warnings; open FH, '<', 'log.log' or die "can't open file\n"; print "Items found under [moo]\n"; while () { if (/^\[moo\]/../^\[cow\]/) { print unless /^\[/; } }