while (<>) { my_sub() if $. > $allowedlines; print; # do the rest of your stuff } #### my $count =0; while (<>) { if ($count++ > $allowedlines) { my_sub(); $count =0; } print; # do the rest of your stuff }