# # Example code, not tested at all! # my %phrases = ( "phrase 1"=>{ qty=1, qtySum=5, qtyCont=8, qtyTotal=\&qtyTotal }, # ... ); sub qtyTotal{ my $qty = 0; my $phrase = shift; foreach my $qType ('qty', 'qtySum', 'qtyCont'){ $qty += $phrases{$qType} if exists $phrases{$qType}; } return $qty; } # and call like this: my $total = qtyTotal($phrases{'phrase 1'});