use re qw(regexp_pattern); my ($pat, $mods) = regexp_pattern($re_ref); If the actual stringification is important or older Perls need to be supported, you can use something like the following: # Accept both old and new-style stringification my $modifiers = (qr/foobar/ =~ /\Q(...