in reply to compound statement

It might help if you tell us what you get and what you expect
Anyway, I get the impression that this part is going wrong
foreach (@totalExoda){ $sum+= $clearedValue; print "$sum\n"; } #end if
I think you want
foreach (@totalExoda){ $sum += $_; print "$sum\n"; } # end of for loop
However, maybe you also want to put this loop outside the first 'for-loop' because your adding values to $sum multiple times this way.
Hope this helps

Cheers
LuCa