Physical writes to pipes are delayed, so you can catch them on the close. the next prints the message. (added the close $P
)
perl -w -e '$SIG{PIPE} = sub {print "SIGPIPE\n";return 1}; if (my $pid=open(my $P, "|-")) { kill("SIGKILL",$pid); sleep(2); print $P "test1:$pid\n";close $P};'