#!/usr/bin/perl use strict; use warnings; my @set = ( { 'id' => '1462', 'items' => [ '9.9', '10.1', '10.3', '10.5', '10.8', '10.94' ], }, { 'id' => '1463', 'items' => [ '3.1', '4.3', '4.5', '4.6', '4.7', '4.8' ], } ); my @aoa; foreach my $hash_ref (@set) { push @aoa, $hash_ref->{items}; } my $totals = sum_up->(\@aoa); sub sum_up { my $aoa = shift; my @totals; #\@totals would look like this: #[ # '13', # '14.4', # '14.8', # '15.1', # '15.5', # '15.74' #] return \@totals; }