#!perl -l my $code = sub { wantarray ? 1 : 0 }; sub wrapper { my @r = wantarray ? &$code : scalar &$code; # ... later # Convert the array to a list to alter the # behaviour when assigning to a scalar. return @r[0..$#r]; } print wrapper; # 1 print scalar wrapper; # 0