open BIG, 'big_file'; my $i = 1; while () { open OUT, ">outfile_" .$i++; #BUG: see follow up below. if ( m/^\$\n$/ ) { close OUT; open OUT, ">outfile_" .$i++; next; } print OUT; } close OUT;