I haven't checked the accuracy of this, but the variables ($platinum, etc) may be undefined. If that is true, the following may help you out (replace your current four lines). It will assure that none of the $myMONEY variables are undefined.
Code:
$myplatinum = (defined($platinum) ? $platinum : 0);
$mygold = (defined($gold) ? $gold : 0);
$mysilver = (defined($silver) ? $silver : 0);
$mycopper = (defined($copper) ? $copper : 0);
edit: I didn't thoroughly read your problem! I think that all you should need to do is add a condition (on the "if ($itemcount.." line) to see if they handed any money also. After you've healed then, you could just return from the sub.