my %has; while(1) { # waiting for new client connection. $client_socket = $socket->accept(); # get the host and port number of newly connected client. $peer_address = $client_socket->peerhost(); ## check against previous connections if (exists $has{$peer_address}) { $has{$peer_address}->{times_connect}=$has{$peer_address}->{times_connect}+1; print "No. of Times it has communicated : $has{$peer_address}->{times_connect}"; } else { print "new connection\n"; $t=1; ++$has{$peer_address}; $has{$peer_address}->{times_connect}=$t; } }