Some advices to improve readability:
Improve your datastructure.
Use the arrow syntax also for assignments.
Name and factor out any reference used more than once $B0_1
Is not good enough.
Consider using push and pop over indexed array access.
Don't quote hash keys dog, cat, bird inside quotes. Use qq{foo"bar"} if necessary
print+qq(\L@{[ref\&@]}@{['@'x7^'!#2/"!4']});