Rewritten with extended functionality in Perl.