http://www.perlmonks.org?node_id=352756

qhayaal has asked for the wisdom of the Perl Monks concerning the following question:

Hello, I have thousands of files, each with thousands of entries. I need to process these files to do the following. Each line in any file has Name, X, Y, Z of an atom. Read each file and find all the pairs of atoms that are within a cut-off distance. I could do it, but the problem was it works too slow!

This was the sequence of steps I followed.
1. Read each file into an array directly.
2. Store X,Y,Z in three arrays.
3. With nested loops, find the pairs within cutoff distance.

What I would like to know is:
A. Is there a way of significantly improving the speed in Perl that involves this kind of math? If not,
B. If I have a fortran code (subroutine) that reads three arrays and then give me output, can I use the object file generated by that program to plugin to Perl?

Thanks in advance for any tips.

Have a nice day.