open (FILE); my $data = 0; my $partnumber = 5; # changes constantly while(){$data++ if ($_ =~ /^SS/)} # to get the number of objects in a file close FILE; my $chunk =($data + $partnumber)/$partnumber ; # to ensure ther are no remainders my $index = 1; open(FILE$index); open (FILE); my $i = 0; while(){ if (m/^SS/){ $i++; if ($i >= $chunk){ $i = 0; close FILE$index; $index++; open (FILE$index); } } print FILE$index "$_"; } close FILE & FILE$index;