#!/usr/bin/perl # http://perlmonks.org/?node_id=1196089 use warnings; use strict; $\ = $/; while(){ chomp; my $dict = $_; $_ = ; my $star = /\*/; my( $head, $tail ) = map length( $_ // '' ), split /\*/, $_; print "head:[$head], tail:[$tail]"; s/\?/[$dict]/g; s/\*/[^$dict]*/; my $qr = qr/^$_$/; print "regex:[$qr]"; (print "loop #:[$_]"), $_ = , (print "[$_]"), $star && substr($_, $head, 0, ' '), (print "[$_]"), $star && substr($_, -$tail, 0, ' '), (print "[$_]"), print "Answer: ", $_ =~ $qr ? "YES" : "NO" for 1 .. ; } __DATA__ ab a?a 2 aaa aab