Perl Port of Ruby's digit_converter