One More Way to Do It: grep:
>perl -wMstrict -le
"my ($foo, $bar);
my ($no_ws, $some_ws, $lotsa_ws) =
('no_ws', ' some_ws ', ' lotsa ws ');
printf qq{'$_' } for $no_ws, $some_ws, $lotsa_ws;
print '';
;;
s{ \A \s+ | \s+ \z }''xmsg
for grep defined, $no_ws, $foo, $some_ws, $bar, $lotsa_ws;
printf qq{'$_' } for $no_ws, $some_ws, $lotsa_ws;
"
'no_ws' ' some_ws ' ' lotsa ws '
'no_ws' 'some_ws' 'lotsa ws'
Update: However, grep as used above has the disadvantage of creating an output list that may be the same size as the input list; Perl then has twice as much data to deal with.
The advantage of a looping statement like
defined and s/^\s+|\s+$//g for LIST;
is that the elements of LIST are operated on in place and no new list is created.