my $sensitive = qr/one/; my $insensitive = qr/one/i; foreach (@words) { my $pattern = some_condition( $_ ) ? $sensitive : $insensitive; if (/$pattern/) { print "Matched: pattern was $pattern and token was $_\n"; } else { print "Unmatched: pattern was $pattern and token was $_\n"; } }