use strict; use warnings; while() { chomp; if ( /((?!Exception\s+Handler|ExceptionHandler).)*Exception/i ) { print "FOUND : $_\n"; } } __DATA__ Line1: Extension: name="Exception Handler" point="ClientDebugGroupExtension" className="com.foo.bar.pluginfwk.extensions.DefaultDebugGroupExtension" instance=Not created params:( packages="com.foo.bar.common.ExceptionHandler;" level="Verbose" description="User interface unhandled exception handler" ) Line2: java.net.SocketException: Software caused connection abort: recv failed Line3: com.mysql.jdbc.CommunicationsException Line4: MESSAGE: Communications link failure due to underlying exception: