my $regex = "the (animals|dogs|cats).+?are ready to eat."; my $compiled_regex = qr/$regex/; # store $compiled_regex in a database # later on, retrieve the $compiled_regex_from_db my $compiled_regex_from_db = [DBI query and unserialize or thaw?]; my $teststring = "the dogs who are friendly are ready to eat."; $teststring =~ s/$compiled_regex_from_db/creatures/;