List Mail (!) wrote:
I want to switch off the significance of special characters when matching an expression in perl,
man perlre, search for quotemeta.
my $a = 'we$rd*f?le.txt'; if ('we$rd*f?le.TXT' =~ /\Q$a\E/i) { print "yup\n"; } if ('we$rd*f?le_txt' =~ /\Q$a\E/i) { print "no, silly\n"; }
Note that you're still doing a substring match, which may or may not be what you want.
All I actually want is a case insensitive string comparison with no characters having any special meaning at all.
Then why not just downcase and compare:
if (lc('we$rd*f?le.TXT') eq lc($a)) { print "of course\n"; }
-- Martijn