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