$code = sub { wantarray ? ("foot","ball") : "soccer" }; sub foo { wantarray ? (&$code) : &$code } $x = &foo(); @x = &foo(); print $x; print @x;