#!/usr/bin/perl # http://perlmonks.org/?node_id=1196089 use warnings; use strict; $\ = $/; while(){ chomp; my $dict = $_; $_ = ; 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 "[$_]"), substr($_, $head, 0, ' '), (print "[$_]"), substr($_, -$tail, 0, ' '), (print "[$_]"), print "Answer: ", $_ =~ $qr ? "YES" : "NO" for 1 .. ; } __DATA__ ab a?*a 2 aacca aaccb