#!/usr/bin/perl use strict; use warnings; use IPC::Open3; # uncomment to handle SIGPIPE yourself # $SIG{PIPE} = sub { warn "Broken pipe\n" }; open3(my $wh, my $rh, undef, qw'echo foo'); # tiny delay, so the command _has_ closed its stdin in the meantime select undef,undef,undef, 0.2; print $wh "foo\n"; # expected to fail in this case close $wh; print "done.\n"; # not reached, except when handling SIGPIPE yourself