in reply to Deadlock occurring, reason unknown

I'm sure I don't understand your code, but one thing looks funny to me. That is, you select a filehandle and then close it. I think you need to select something else somewhere, because a filehandle remains selected even after it has been closed.

In unix, this can sometimes go unnoticed because the filehandle for the next file that is opened will be the next one that is available, which may be the one that you last closed.

Here is some code that shows the idea:

use strict; open(IN, "datafile") or die "can't open datafile"; local $/= 1; select(IN); $_= <IN>; close IN or die "can't close IN"; print "datafile:\n", $_ or die "can't print";
This code dies with a can't print because IN is still selected. This example is repaired by adding a select STDOUT statement right before the print.

You may want to add error checking to your code not just for your open commands, but also on your print and close statements.

It should work perfectly the first time! - toma