my $total=0; # running total foreach (@temp) { my ($instan, $value) = (split /\*/, $_); my $k = $key . ":" . $instan; $total += $value; # total for each iteration $DM_D{$k} = $total; }