my @AoA = ( [1..10], [2..11], [3..12] ); my %h; foreach my $i ( 0..#@AoA ) { vec($h{$_},$i,1) = 1 for @{$AoA[$i]}; }