my $val = abs($num); do { push @ret, $chars[$val % $base]; $val = int($val / $base); } while $val; push @ret, '-' if $num < 0;