#!/usr/bin/perl -wl use strict; my @numberarray = qw(000000 000002 001110 010201 010010 001000 000120 010030); for (@numberarray){ next if $_ == 0; my @array = split //; my $incr = 0; while ($array[0] eq 0) { shift @array; $incr++; } unshift (@array,"\x20" x $incr); print @array; }