Ok, so I modified you example a little bit. Didn't change anything except the way it's structured. The way you did it makes sense but is a little hard for me to read, and possibly maintain later if I ever have to change something.
Here is what I modified to:
for (my $x = $#temp; $x >= 0; $x--)
if ( substr($temp[$x-1], 0, -1) eq substr($temp[$x], 0, -1))
$temp[$x-1] += $temp[$x];
splice @temp, $x, 1;
Does the same thing just a little more long winded and simpler for a noob..
Thanks Again for Your Help,