seeing your code, i assume you're on a unix like machine. Try to set the nice level of your program. If it's the only running process, it still takes a lot of cpu-time, but if another program with a higher nice level gets in, it reduces it's load.
Since you use system commands, you could run them like
...
if ($nicelevel ne "") {
$cmd = "nice -$nicelevel " . $cmd;
}
system $cmd;
Or You could look
here
"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.