Here is a simple base converter, with less than 10 lines of code, it gives you what you wanted and more. It is not difficult for you to continue from here and extract the specific digits, substring() if you wish.
use strict;
use warnings;
for (2 .. 9) {
print "base $_: " . convert(162, $_), "\n";
}
sub convert {
my ($value, $base) = @_;
my $converted = "";
while ($value) {
$converted = ($value % $base) . $converted;
$value = int($value / $base);
}
return $converted;
}
This gives:
base 2: 10100010
base 3: 20000
base 4: 2202
base 5: 1122
base 6: 430
base 7: 321
base 8: 242
base 9: 200