sub processit { my( $lclient, $lfileno, $lpeer ) = @_; my $sel_cli_id = $num_of_client; ######### This is never used. if( $lclient->connected ){ while( <$lclient> ) { ### $peerC si shared by cloning ### It sole purpose appears to be to allow you to share ### a single thread proc by two different types of thread. if( $peerC eq '127.0.0.1' ) { my(@comm) = split(/:/, $_); ### These 3 lines is better as one my $sel_clix = $comm[0]; my $commandC = $comm[1]; my $sel_cli2; ### This will only see a copy of whatever is in @MDevices ### when this thread is spawned. ### And none of teh subsequent changes! ### You'd be far better avoiding a linear search by using a hash for( my $p=0; $p <= $#Mdevices; $p++ ) { if( $Mdevices[ $p ][ 0 ] eq $sel_clix ) { $sel_cli2 = $Mdevices[ $p ][ 1 ]; } } ### A loop that iterates a single thing?? foreach my $fn ( $sel_cli2 ) { if( $sel_cli2 ) { open my $fh, ">&=$fn" or warn $! and die; print "\n $lclient $sel_cli2 Command ", "sent to: $sel_clix Command: $commandC"; print $fh "$commandC\n" } else { print "\n $lclient Device: $sel_clix", "NOT avaiable to receive command\n"; } } } else { print "COMMAND RESPONCE: $_"; } } } close( $lclient ); #### Modifying a shared variable without locking it #### Will cause problems. @clients = grep{ $_ !~ $lfileno } @clients; }