for (my $i = 0; $i < scalar @{$self->{'trolley'}}; $i++) { if (${$self->{'trolley'}}[$i]->{'id'} eq $id) { $self->{'intent'} = undef; splice $self->{'trolley'}, $i, 1; return scalar @{$self->{'trolley'}}; } } #### for ( my $i = $#{ $self->{ trolley } }; $i >= 0; --$i ) { if ( ${ $self->{ trolley } }[ $i ]->{ id } eq $id ) { $self->{ intent } = undef; splice @{ $self->{ trolley } }, $i, 1; return scalar @{ $self->{ trolley } }; } }