$lines=scalar@data/4; for ($t=1; $t<=$lines; $t++) { for ($i=1; $i<=4; $i++) { $items=shift(@data); print $items; }