#!/usr/bin/perl -w require 5.005; use strict; use IO::Socket; for(1..100000) { open_sock(); } exit; sub open_sock { my $answer; my $sock=IO::Socket::INET->new(PeerAddr=>'10.118.32.31', PeerPort=>1955, Proto=>'tcp', Timeout=>20)|| die("Failed to open socket.\n"); # Writing to the socket makes no difference. #print $sock "x"; # Reading from the socket closes the memory leak. # Nothing gets printed on STDOUT from the print statement, # i.e. there was nothing to read. Right? while(defined($answer=<$sock>)) { print("Answer: $answer\n"); } close($sock); }