use warnings; use strict; use IO::Socket; my $socket = new IO::Socket::INET ( LocalHost => 'localhost', LocalPort => '8888', Proto => 'tcp', Listen => 1, Reuse => 1, ); die "Could not create socket: $!\n" unless $socket; $|++; while (1) { my $incoming = $socket->accept(); while(<$incoming>) { print $_; } print "\nNext session.\n"; } close($socket); #### $ nohup ./listen.pl >listen.log 2>listen.log & #### $ telnet localhost 8888 Trying ::1... telnet: connect to address ::1: Connection refused Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. You there? ^] telnet> quit Connection closed. #### $ cat listen.log You there? Next session. #### $ jobs [1]+ Running nohup ./listen.pl > listen.log 2> listen.log &