Possibly with the
map function:
my @infoArray = (1, 2, 3, 4, 5, "\n", 6, 7, 8, 9, 10, "\n");
my @final_array = map { $_ eq "\n" ? $_ : "$_\t"} @infoArray;
# now print @final_array, for example:
print join '', @final_array;
which prints:
1 2 3 4 5
6 7 8 9 10
Or you could print directly the output of map:
print join '', map { $_ eq "\n" ? $_ : "$_\t"} (1, 2, 3, 4, 5, "\n",
+ 6, 7, 8, 9, 10, "\n");
giving the same output.
Update (Apr 08, 2014 at 17:15 UTC): added the output and the one-line final piece of code (did not have Perl on my tab when I wrote the original post while in public transportation).