foreach $x (@ordered){ substr($x,0,6))=sprintf("%06d", $count++); }