my @array = ( 'hi there ', ' this and that ', ' and the other thing ', ' blah blah blah ', ' one two there ', ' four five six '); map { s[(^\s+|\s+$)][]g }@array;