in reply to searching through data

I found that sorting @array takes a significant amount of time when there are 400000 elements.

Given that your search loops don't depend on it being sorted, I'd suggest removing that "optimisation" and seeing how that affects your timings.

As an aside, how many lines are there in your input file?

--
use JAPH;
print JAPH::asString();