in reply to simple math

You are doing everything right except assigning the first value to $result; try $result = shift(@_) just before the foreach.