#!/usr/bin/env perl use strict; use warnings; use List::Util 1.45 'uniqstr'; use Test::More; my @tests = ( ['abc', abcdefa => 0], ['def', abcdefa => 1], ['abc', abcdef => 1], ['xyz', xyz => 1], ['xyz', zzz => 0], ['xy', zzz => 1], ); plan tests => 0+@tests; for my $test (@tests) { my ($tmpl, $str, $exp) = @$test; my %tmpls = map +($_ => 1), split //, $tmpl; my @chars = split //, $str; my @tmpl_chars = grep exists $tmpls{$_}, @chars; is 0+@tmpl_chars == uniqstr(@tmpl_chars), !!$exp; }