in reply to Re^3: How to print 5 lines below after a regex match
in thread How to print 5 lines below after a regex match

It really depends on what the OP really needs, but there is a danger of $flag being reset while it is reading the next "few" lines, if the regex matches again. Perhaps something like this:
use strict; my $few = shift || 3; while (<DATA>) { if (/Update certificate/) { print $_; print scalar <DATA> for 1..$few; } }
Or possibly for 1..$few-1;, depending on whether $few includes the matching line or not.