Sounds fairly straightforward.
Can't call next_hit on an undefined value, so therefore $result is currently undefined.
You set $result just above that line using: my $result=$in->next_result;
So, the logical reason would be that next_result is returning undef. Perhaps because there are no further results to return.
You should check return values for error values before using them.