my $case = shift; my $pattern = $case ? qr/$pattern/i : qr/$pattern/; if (/$pattern/) { # code }