$SIG{PIPE} = sub { $error = "Lost connection - broken pipe." }; # your eval wrapped code here (YMMV) return $error if ($error);