Rewrite regen-modules in Perl.

This also fixes the versioning issue we were having with older modules.