# use liz's technique foreach my $i ( reverse 0 .. $#AoH_all ) { if ( $exclude{ $AoH_all[$i]{id} } ) { splice @AoH_all, $i, 1; } } # keep track of things manually my $n_elt = @AoH_all; for ( my $i = 0; $i < $n_elt; ++$i ) { if ( $exclude{ $AoH_all[$i]{id} } ) { splice @AoH_all, $i, 1; --$n_elt; # whoops, bug here, see update... } } # finally, perl updates the length of @AoH_all for us, so: for ( my $i = 0; $i < @AoH_all; ++$i ) { if ( $exclude{ $AoH_all[$i]{id} } ) { splice @AoH_all, $i, 1; # whoops, bug here, see update... } }