use threads (); use DBI; use DBD::Oracle; my $thrds=25; my $iter=11; my @threads; for (my $j=0; $j<$iter; $j++) { &start($j); } sub start { my $k=$_[0]; for (my $i=0; $i<$thrds; $i++) { $threads[$i] = threads->new(\&RunThread,$k, $i); } for (my $i=0; $i<$thrds; $i++) { $threads[$i]->join; } } sub RunThread { my $dbh = DBI->connect("dbi:Oracle:ora", "user","pass") or die "failed connect"; my ($x, $y)=@_; open (my $fh2, ">/tmp/da-$x-$y") or die "failed in thread $! at iter $x thread $y " ; close ($fh2); $dbh->disconnect or die "disconnect failed"; }