Your code is nearly impossible to read. Please use CODE tags in your post, and a reasonable indentation scheme.
One apparent problem outside of that, you say $subject is an array. You probably mean arrayref, but anyway using an arrayref as a hash key works, but probably doesnt give you the results you're looking for.
I use the most powerful debugger available: print!