my @strings = ( "ERROR blah license will expire", "ERROR blah something else", "ERROR blah Error processing Cancel Execution", ); foreach (@strings) { if (!($_ =~ /^ERROR.+?(Error processing Cancel Execution|license will expire)$/)) { print "Do something with '$_'\n"; } }