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


in reply to Issue on covariance calculation

Opening and closing a file is quite time consuming on most operating systems. Your code opens and closes "Outfile.txt" 10,000 times, once for each input line. You also have to find the end of the file each time you open it, which will take quite a while as the file gets large.

Try taking the open and close for that file outside the "for my $element" loop, so it's opened and closed only once. That should speed things up a lot.