#!/usr/bin/perl -w use strict; use Algorithm::Loops qw(NestedLoops); my @symbol = ( [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ], [ 'a', 'b', 'c' ], [ 'c', 'd', 'e' ], ); my @all; my $iter = NestedLoops(\@symbol); my @list; while (@list = $iter->()) { my @sortedList = sort @list; my $listString = join ('',@sortedList); push @all, $listString; } my @uniq = keys %{{ map { $_ => 1 } @all }}; my @sortedUniq = sort (@uniq); foreach my $sortedUniq (@sortedUniq) { print $sortedUniq,"\n"; } #### for my $symbolRow (0..$#symbol) { for my $symbolCol (0..$#{$matrix[$symbolRow]}) { # If, for elements 1..$#{$matrix[$symbolRow]} #the element (symbol) already exists in a preceeding line #remove from current line. # Then proceed with nested loops.