Add Perl port, cribbed mostly from Python.
Merge pull request #21 from schmonz/master

Add Perl port, cribbed mostly from Python.