sub RunThread { my $tid = threads->tid; my $dbh = DBI->connect("DBD::Pg",...) or die "failed connect"; my ($x, $y)=@_; open (my $fh2, ">/tmp/da-$x-$y") or die "failed in thread $! at iter $x thread $y " ; print "$tid : ", fileno( $fh2 ); sleep 1; close ($fh2); $dbh->disconnect or die "disconnect failed"; } #### [19:04:06.98] c:\test>DBjunk.pl 1 : 3 2 : 4 3 : 5 4 : 6 5 : 7 6 : 8 8 : 9 10 : 10 9 : 11 7 : 12 12 : 13 14 : 14 13 : 15 11 : 16 15 : 17 16 : 3 17 : 4 19 : 5 18 : 6 20 : 7 21 : 8 22 : 9 23 : 10 24 : 11 25 : 12 27 : 3 28 : 4 26 : 5 29 : 6 30 : 7 31 : 8 32 : 3 33 : 4 34 : 5 35 : 6 36 : 7 37 : 8 38 : 9 39 : 10 40 : 11 41 : 12