in reply to Loops and variables?

Your question is very confusing. Variables can't be stored in a function, for starters. (Well, there are closures, but let's avoid advanced topics of no immediate relevance.) Maybe one of the following snippets will answer your question:

# Modifies @array in-place. foreach (@array) { $_ = sprintf($format, $_); }
# Copies to a second array while formatting. my @formatted = map { sprintf($format, $_) } @array;
# Same as last, but without using "map". my @formatted; for (0..$#array) { $formatted[$_] = sprintf($format, $array[$_]); }

Does that help?

To print the pre-formatted data, simply use the following:

foreach (@formatted) { print($_, "\n"); }