Is there a way to precompile a regex in Perl? I have one that I use many times in a program and it does not change between uses.
for clarification, you can user precompiled regex as:
my $re = qr/foo|bar/; #precompile phase
if ( $string =~ $re ) ... #for direct use
if ( $string =~ /$re/ ) .... #the same as above but a bit complicated
if ( $string =~ m/something $re other/x ) ... #for use precompiled as a part of bigger regex
if ( $string =~ s/$re/replacement/ ) ... #for direct use as replace
if ( $string =~ s/some $re other/replacement/x ) ... #for use precompiled as a part of bigger, and as replace all at once
It is documented in perlre but there are no direct examples.