use strict; use warnings; while () { print "$1\n" if !/^TAGS/ && /(.*?)(?=TAG2)/; }