sub nonblank { return grep { /\S/ } @_ } print nonblank('foo'); # list context through print() print $_ for nonblank('foo'); # explicit list context my $temp= nonblank('foo'); # scalar context print $temp; # still scalar ( $temp)= nonblank('foo'); # list context, discarding all but the first element print $temp; # First element of that list $temp= (nonblank('foo'))[0]; # Scalar context in assignment, but we only take the first element explicitly print $temp;