foreach my $hostname (@host) { my $thr = fork(); if($thr) { #parent push(@childsall, $thr); next; } else { connecttohost($hostname); } } foreach my $child_pid (@childsall) { my $tmp = waitpid($child_pid, 0); } sub connecttohost { my($hname) = @_; my $query = sprintf("SELECT * FROM $DbName WHERE ue_id='$hname'); my $hash_ref = $::dbh->selectrow_hashref($query); }