use Regexp::Trie; my $rt = Regexp::Trie->new; while() { $rt->add($_); } $rt = $rt->regexp;