Hi all,
Is there a way to pass a variable that tells the regex to toggle case-sensitivity (with or without the i switch)?
my @words = qw/one One/;
my $pattern = 'one';
foreach (@words) {
# case-sensitive so 'one' is matched but not 'One'
# but I would to to be able to enable case-sensitivity
# in some cases to match both 'one' and 'One'
if (/$pattern/) {
print "Matched: pattern was $pattern and token was $_\n";
}
else {
print "Unmatched: pattern was $pattern and token was $_\n";
}
}
Thanks in advance :)
Update: Thanks to dave_the_m and tlm. Got it to work as follows:
my $case = shift;
my $pattern = $case ? qr/$pattern/i : qr/$pattern/;
if (/$pattern/) {
# code
}