my @nums = qw(000001 000010 000100 001000 010000 100000); foreach (@nums) { s/^(0+)/' ' x length $1/e; print "|$_|\n"; }