# $msg is the message to send, it is guaranteed < PIPE_BUF and ends in \r\n my $sigpipe = 0; local $SIG{PIPE} = sub { $sigpipe = 1; }; my $sent = print $child_writer $msg; if (!$sent && ($!{EPIPE} || $sigpipe)) { warn "Write to child_writer failed with EPIPE - child died ($sigpipe)"); # restarts child writer } else { warn "Write to child_writer failed - $!"; }