while (<>) { my $match = /^Success.*Id-/i ... /^Success/; print if $match && $match !~ /E/; }