while (my $train = ) { while (my $predict = ) { ... } seek predict, 0, 0; // need to return to the start of the predict file!!! }