#!/usr/bin/env perl use strict; use warnings; my $VAR1 = { '153-1' => { '19-4' => { 'cost' => '6300.00', 'cost2' => '630.00' }, '135-1' => { '68-4' => { 'cost' => '300.00', 'cost2' => '130.00' } }, '1069-9' => { }, '35-1' => { '28-4' => { 'cost' => '30.00', 'cost2' => '10.00' } }, } }; my $total = 0; get_total_cost($VAR1, \$total); printf "Total = %.2f\n", $total; sub get_total_cost { my ($hash_data, $sub_total) = @_; for my $key (keys %$hash_data) { if (ref $hash_data->{$key} eq 'HASH') { next unless keys %{$hash_data->{$key}}; get_total_cost($hash_data->{$key}, $sub_total); } else { if ($key eq 'cost') { $$sub_total += $hash_data->{cost}; } } } return; }