while( $xfactor > 0 ){ my $newfile = sprintf 'new-x-%d-%d', $xfactor, $nimblefoot; MahFourThousand( $newfile, $xfactor, $nimblefoot ); $xfactor--; } sub MahFourThousand { my $counter = 0; while( $counter < 4000 ){ ## print one line $counter++; ## print 10 lines $counter += 10; ... } }