in reply to sprintf formatting doubt
perl -e '$a=150; $b=6; print sprintf "%0*d\n",$b,$a;' 000150 [download]