#! perl -slw use strict; sub p{ my @a = split '', shift; while( @_ ) { my @c= split '', shift; my @b=(); for my $c ( @c ) { push @b, $_ . $c for @a ; } @a = @b; } return @a; } my @combs = ( p( 'NT', 'GCATN', 'NG', 'NC', 'NG', 'NT', 'NG' ), p( 'NG', 'NT', 'NG', 'NC', 'NG', 'GCATN', 'NT' ), p( 'NA', 'GCATN', 'NC', 'NG', 'NC', 'NA', 'NC' ), p( 'NC', 'NA', 'NC', 'NG', 'NC', 'GCATN', 'NA' ), ); my %seen; @seen{ @combs } = (); print "The number of unique 7-char sequences that can be matched by the regexes is:", scalar keys %seen;