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"; }