#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11157093 use warnings; $| = 1; # NOTE # slightly reformatted from your code - $sock not needed while( my $cmd = <> ) { if( $cmd =~ m/^sleep (\d+)/ ) { my $snooze_time = $1; printf "Will sleep for $snooze_time seconds\n"; sleep $snooze_time; print "... ZZZ ... Yawn ... What next oh master?\n"; } # NB: In real life there are lots of other commands and many take some time to process. else { print "I did not understand that. What next oh master?\n"; } } __END__ # # unlisted service # (goes in /etc/xinetd.d) NOTE change user, server, and only_from # if this file changed, use 'systemctl reload xinetd' so prev still run # using 'restart' will kill running servers, 'reload' will not # service unlisted-pm11157093 { type = UNLISTED socket_type = stream protocol = tcp wait = no user = rick log_type = FILE /dev/null server = /home/rick/code/pm11157093.pl port = 1234 disable = no only_from = 127.0.0.1 192.168.1.0/24 }