use strict; use warnings; my @sets = ( [0], [0, 1], [0, 1, 2], [1, 2, 3], [5, 6, 4], ); my @clusters; foreach my $set (@sets) { push @clusters, Set::Scalar->new->insert(@$set); } for my $i (0.. $#clusters) { ...