Greetings all,
At first glance this reminds me of MatLab code, matrix algreba sort of stuff. With that in mind you might find PDL useful. I am not sure if you are using 'A','B','C' as an example but if you are interested in using strings there is a module for that as well, PDL::Char.
-InjunJoel
"I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo