my $strLen = 0; for (my $x = 0; $x <= $#AoA; $x++) { #If the current line is an owner then there will only be 10 elements. if ($AoA[$x][0] eq 'OWNER') { $waitline = 10; } #ELSE the line is a user waiting and we should add the time waiting to the end of that line, 11 total elements. else { $waitline = 11; } for (my $y = 0; $y <= $waitline; $y++) { $strLen = $colLengths[$y]; printf OUTDATA "%-${strLen}s ", $AoA[$x][$y]; } print OUTDATA "\n"; }