sub set_stock { my( $self, $supplier, $line, $stockLevel ) = @_; my $supplierList = (); my $supplierNumber = $supplier->supplier_id; # $supplierList will be a reference to an array of references to hashes. unless( $supplierList = $self->get('supplier_list') ) { die( "Cannot set stock level when supplier list is corrupt: $supplierList" ); } foreach my $supp (@$supplierList) { next unless( $supp->{supplier_id} == $supplierNumber ); my $reference = $line->reference; # Here is the update. $supp->{$reference} = $stockLevel; } }