Don't call import because that only makes sense at compile-time. Call the binsearch function using its full name, and forcibly ignore its prototype...
SKIP: {
eval { require List::BinarySearch }
or skip "List::BinarySearch not installed", 2;
$index = &List::BinarySearch::binsearch(
sub {$a <=> $b},
300,
@num_array,
);
# ...
}
Alternatively, split the tests which use binsearch into a separate test file, and in that file use:
use Test::Requires "List::BinarySearch";
... which will automatically do the right thing in terms of skipping, importing at compile time, etc.