use Errno ':POSIX'; $SIG{PIPE} = 'IGNORE'; for (1 .. 3) { unless (print SOMEPIPE "blah") { last if $! == EPIPE; # terminate the loop if reader goes away die "I/O error: $!"; # this is more serious, so die } }