in reply to bug or curly bracket hell?

Unfortunately, the code you've posted here does not compile. As far as I can tell, you've got an elsif followed by an else, followed by another elsif. Perhaps you have a closing curly and else missing on the outer if, but it's really hard for me to tell where because the code you've posted is also 256 lines long.

In order to get the most efficient help possible, please first fix your code so that it at least compiles. Also, you should always Use strict and warnings, since that will help you avoid other mistakes. And I recommend you use perltidy to format your code so that the indentation is better, this will also help you spot issues like missing braces much faster. If you follow all of this advice, we will very likely be able to help you quite quickly. In addition, providing some short but representative sample input with the expected output for that input would be very helpful. "Representative" in this case means especially that each branch of your multiple if-elsif-elses should be exercised by the sample input. See also SSCCE.

Another thing that will shorten your code significantly is if you take the many, many lines that look like $worksheet2->write($rowCount2+1, 1, $t[1]); and turn them into a loop, such as $worksheet2->write($rowCount2+1, $_, $t[$_]) for 1..11;. I see that in each case you're replacing a different element with something from @ary, which is something you could probably also do by assigning to the appropriate element of @t before that loop - due to the length of the code it's a little difficult for me to tell if that works with all of your logic, but in the worst case you could always just make a temporary copy of @t and modify that.