in reply to pattern matching with substring containing special character

Replace the Xs with a character class match [ABCD] then use the resulting string as the match string:

use strict; use warnings; my $match = "ABCDABCDXBCDABCXABCDXXCDABXD"; my $str = "ABCDABCDABCDABCDABCDABCDABCDABCDABCDABCD"; $match =~ s/x/[abcd]/ig; print "Matched $1\n" if $str =~ /($match)/i;

Prints:

Matched ABCDABCDABCDABCDABCDABCDABCD
True laziness is hard work

Replies are listed 'Best First'.
Re^2: pattern matching with substring containing special character
by Anonymous Monk on Mar 03, 2011 at 01:36 UTC
    Oh yes, great, I accidentally wrote "*" instead of "." as you pointed out... GrandFather, thanks also for your recommendation, good to learning new tricks!