Please send me comments on how to improve this. My next try would include using '&' instead of '^'.
The one thing that I did try was swaping variables in '$z' and '$Z' and in the print. It doesn't matter how you '^' them as long as you use all of the variables '$a', '$A', '$b', and '$B'. That suprised me until I thought about it some more.