Looks like your tests are on $blast_results, not $results. Is $blast_results a valid object that can call a method called next_result? How does next_result indicate that there are no more results? Is it possible that it would return undef for this condition?