in reply to loop da loop chomp chomp loop chomp blurp oops

You might also want to do a close( FILEOUT ) or die("Couldn't close file $i: $!"); after printing the single line, before opening the next output file.