my %hash; OBJ: for my $obj ( @objects ) { my $fingerprint = $fingerprint{$obj}; my $class = \@{$hash{$fingerprint}} for( @$class ) { if( same($obj,$_->[0] ) { push @$_, $obj; next OBJ: } } push @$class, [ $obj ] }