... while(defined(my $trained = )){ chomp $trained; while(defined(my $predict = )){ chomp $predict; ... } ... }