#!/usr/bin/perl -w use strict; my %hash = ( foo => '123' , bar => '234', batz => '345', bongo => '100' ); #send reference to hash, and list of keys to sum print sum_hash( \%hash, 'foo', 'bar', 'batz' ) . "\n"; #send reference to hash, will sum all numeric values print sum_hash( \%hash ) . "\n"; sub sum_hash { my $t_hash = shift; my $total; if (@_) { for (@_) {$total += $t_hash->{$_}; } } else { for ( keys %$hashref ) { $total += $t_hash->{$_}; }; } return $total; }