use strict; my $flag = 0; my $few = shift || 3; while () { $flag = $few if (/Update certificate/); print $_ if ($flag-- > 0); }