... # Instead of eval block use our new function call my ($msg, $bcount, $error) = read_msg($read_ready->[0]); # Check for errors and empty messages die $error, "\n" if ($error); die "Nothing received!\n" if ($bcount == 0); ...