#!/usr/bin/perl -w use strict; my $Usage = "Usage: $0 line_count input.file output_name\n"; ( @ARGV == 3 and $ARGV[0] =~ /^\d+$/ and -f $ARGV[1] ) or die $Usage; my ( $line_limit, $infile, $outname ) = @ARGV; my $outid = 0; open( I, $infile ) or die "$0: open for input failed on $infile: $!\n$Usage"; while () { if ( $. % $line_limit == 1 ) { close OUT if ( $outid ); my $outfile = sprintf( "%s.%03d", $outname, ++$outid ); open( OUT, ">", $outfile ) or die "$0: open for output failed on $outfile\n"; } print OUT; } close OUT;