my %seen; for my $i (reverse (0 .. @$ref-1)) { # replaces current item in array with last item # and removes the last element if id already seen $ref->[$i] = pop @$ref if $seen{$ref->[$i]->{id}}++; }