#!/usr/bin/perl use strict; # https://www.perlmonks.org/?node_id=11154445 use warnings; use IO::Socket; use IO::Select; my $port = shift // 3333; # FIXME my $listen = IO::Socket::INET->new( LocalPort => $port, Listen => 100, ReusePort => 1,) or die $&; my $sel = IO::Select->new( $listen, *STDIN ); print "Hit to quit\n"; for( my $more = 1; $more; ) { for my $handle ( $sel->can_read ) { if( $handle eq *STDIN ) { $more = 0; print "operator wants me to go away\n"; } else { my $live_socket = $listen->accept; while( <$live_socket> ) { # process stuff here print "GOT: $_"; /^\r?\n\z/ and shutdown $live_socket, 1; # NOTE because testing with GET } close $live_socket; } } }