Here is a way that you can get a list of all elements, without any leading OR trailing whitespace.
This is works even if the element itself has whitespace in the middle.
my @trimmed_array = map { /^\s*(.+?)\s*$/ } @array;
In place editing of the array would prob be prefered though
s/\s*$// for(@array);
Wonko