# This could be loaded from a file, a db, whatever. $uncompiled_regexp = 'a.*b'; $text =~ /$uncompiled_regexp/; # If you plan on using the regexp many times, compile it! $compiled_regexp = qr/$uncompiled_regexp/; $text =~ $compiled_regexp;