This is very much not a Perl question. You're trying to do a global multiple alignment with a penalty for misaligned domains? I'm not sure why this additional penalty would help, but I'm not the one working on the problem. One hack you could try is just to pad the domain boundaries with something, so misaligning domains would cause mismatches. Print it out, run your tool, read it back in.
If that doesn't work, and if there isn't some existing tool that does what you want, you'll probably just have to write your own. I don't think this is a standard problem, so you'll probably end up here.