$hash{$_} = [ ( $hash{$_}->[0] || 0 ) + $numbers[$i++], ( $hash{$_}->[1] || 0 ) + 1 ] foreach @sequence; print $_, ( $hash{$_}->[0] / $hash{$_}->[1] ) foreach keys %hash;