http://www.perlmonks.org?node_id=642997


in reply to Re: searching for a string w/ a * in any single position?
in thread searching for a string w/ a * in any single position?

I think the following will do the trick:

my @chars = map quotemeta, split //, $word; my $re = join '|', map { local @_ = @chars; $_[$_] = '.'; join '', @_ } 0..$#chars;

Using Regexp::Assemble should be faster:

use Regexp::Assemble qw( ); my @chars = map quotemeta, split //, $word; my $ra = Regexp::Assemble->new(); for (0..$#chars) { local @_ = @chars; $_[$_] = '.'; $ra->add(join '', @_) } my $re = $ra->re();