use strict; use warnings; use Math::Combinatorics qw( permute ); use Test::More; my @match_wanted = qw( abc bca cab cba bac acb ); my @match_unwanted = qw( aab abbc acc ); my @charset = qw( a b c ); my %valid = map { join( '', @$_ ) => 1 } permute( @charset ); sub match { my $s = shift; return( exists $valid{$s} ? 1 : 0 ); } plan 'tests' => ( scalar @match_wanted + scalar @match_unwanted ); ok( match( $_ ), "matches '$_'" ) for @match_wanted; ok( ! match( $_ ), "does not match '$_'" ) for @match_unwanted;