#!/usr/bin/perl -w use strict; use AnyEvent; use AnyEvent::Socket; use AnyEvent::Handle; use File::HomeDir; my $log_socket = File::HomeDir->my_home . '/var/log.sock'; my $cv = AnyEvent->condvar; tcp_connect 'unix/', $log_socket, sub { my ($fh) = @_ or die "Unable to connect: $!"; my $h; $h = new AnyEvent::Handle fh => $fh, on_eof => sub { $h->destroy; $cv->send; }, on_error => sub { die("Connection closed."); }; while () { $h->push_write($_); } $h->on_drain (sub { undef $h; $cv->send; }); }; $cv->recv;