while ( <> ) { if ( my $c = /^(mykeyword1|mykeyword2)$/../^\Q***END***\E$/ ) { next if $c == 1 || $c =~ /E/; print; } }