in reply to loop array excluding some elements

grep in list context (eg, used in a for) will create a new list by selecting elements in its input that match a condition. IE:

foreach (grep { $_ != 0 } @SlectedColumns[1..$NrCoumns]) { # Only non zero elements here }

Edit: and if your input is only numbers, and the content of the loop is just one EXPR, you can even write: print "I'm priting $_!\n" for grep $_, @SlectedColumns[1..$NrCoumns];