my $id = shift; # disallow ID 0; $id > 0 && $id < 1e9 or return q(); $id = sprintf '%0*lu', ($id < 1e6 ? 6 : 9), $id; ...