That almost sounds like the use case for the WhiteSpace option. Did you try that?
If you still have problems, I recommend that you show precisely how your arrays are created. eg:
my @array1 = ('abc ', 'xyz');
... and so on. This removes any ambiguity about the data you actually have.