my $pattern = qr{ab[crdnfqm]def}; if $string =~ m{ ($pattern) }; ....