use strict; use warnings; while ( ) { print if m{^L[13](?!.*?TEXT)}; } __DATA__ L1 04:10:07.915 LOG: Want this Line1 L3 04:10:07.915 LOG: Want this Line2 L1 04:10:08.024 LOG: TEXT. Do not want this Line3 L3 06:37:58.163 LOG: TEXT. Do not want this Line4 L3 07:02:36.921 LOG: Want this Line5 L4 08:02:30.910 LOG: Do not want this Line6 L5 08:02:36.943 LOG: Do not want this Line7 L6 09:02:38.811 LOG: Do not want this Line8 #### L1 04:10:07.915 LOG: Want this Line1 L3 04:10:07.915 LOG: Want this Line2 L3 07:02:36.921 LOG: Want this Line5