in reply to syntax error near print

A couple of style comments may help:

Use three parameter open and lexical file handles (open my $out, '>', "$outfile") or die "Cannot open $outfile :$!";). The lexical file handle would have caught your OUT/OUTFILE issue at compile time.

Use "early exits" to make code clearer and to avoid extra levels of nesting. The case in point is your "No hits found" test. By rewriting it as:

if ($result->num_hits == 0) { #"No Hits found" case: print OUT "\n No hits found \n"; next; }

you don't require the else part of the statement - that code simply follows the if and is executed only when the if condition is false (the next following the print statement effectively skips the following code).

True laziness is hard work