There are a few things I can see (for instance not loading your result into the file immediately), but I suspect the main performance benefit you will get will probably be from using a different regex. To that end, do you have a better idea what the data output format from your program is?
Here's some sample perl that may run a little bit quicker:
use strict;
foreach my $arg (@data){
my @score=();
open(my $fh, "program $arg $arg1 |");
while (<$fh>) {
chomp;
if (/\d+.+\s+((\d+)?\.?\d+)/o) {
push(@score, $1);
}
}
close($fh);
my @sorted = sort { $a <=> $b } @score;
}
Notice a few things here:
- I'm using a program file handler so that I'm not using a temporary file, thus skipping a whole pass of data.
- I changed the regex to use nested groups rather than multiple options.
- I use strict and keep package names (for the love of God use strict in your perl).
The other people have said to use threads. You DO NOT need to do this, as running the process as I have done with the trailing pipe (|) in the open function causes perl to fork a process for you. Then you use standard unix pipes to read from the program asynchronously.