my %regexen = ( v => qr/[aeiou]/i; c => qr/[a-z^aeiou]/i; ); # This is inputted somehow. my $pattern = 'cccv'; my $regex = join '', map { $regexen{$_} } split //, $pattern; # Get @dictionary somehow. foreach my $word (@dictionary) { print "$word matches" if $word =~ /$pattern/; }