@tree1=@samples[0..2]; ... (another 10 of those) @tree12=@samples[33..35]; for ($z = 1; $z <= 12; $z++) { $arrayname="tree$z"; foreach $patch(@$arrayname) { ... do something }