my $count=0; foreach my $e (@$aref){ $count++; if ($count==4){ $count=1; print "\n"; } print $e,"\t"; }