my $max = 10; my $num = 0; my @lines; while () { last if ++$num > $max; push @lines, $_; }