LINE: while ( defined( $_ = <$Rlog> )) { s/^Alert Level\s0*(?:[3-9]|\d{2,})/(?!.*Log Entry)/DEREK!!!!\n$&/s; } continue { print $Plog $_; }