my @x = (1,2,3,4,5,6); my @new; foreach my $x (@x) { push(@new, sprintf("%7d", $x)); } print STDOUT join(" ", @new), "\n"; #outputs: 1 2 3 4 5 6