$code = sub { wantarray ? ('foot','ball') : 'soccer' }; sub foo { my ($r, @r); # two possible returns (wantarray ? (@r) : ($r)) = # slight of hand to get the correct lvalue (wantarray ? (&$code) : &$code); # and make the correct rvalue call return $r || @r # return that which is defined } $x = &foo(); @x = &foo(); print $x; print @x; #### $code = sub { wantarray ? ("foot","ball") : "soccer" }; sub foo { wantarray ? (&$code) : &$code } $x = &foo(); @x = &foo(); print $x; print @x;