#!/usr/bin/perl -w use strict; use IO::Socket; my $host = 'localhost'; my $port = 9000; my $client; my $listen = new IO::Socket::INET->new( Proto => 'tcp', LocalPort => $port, Reuse => 1, Listen => 5, ) or die "Can't start server"; while ($client = $listen->accept()) { open OUT, ">>/home/john/perl/daemonlog" or die "Can't open OUT: $!\n"; while (<$client>) { chomp; print $client "Thank you for your command: $_\n"; print OUT $_; if ($_ eq "quit") { close OUT; close $client; } } } close $listen;