Yes, you are looking for wantarray :
use strict; use warnings; sub foo{ if(not defined wantarray){ print "Called in void context!\n"; } elsif(wantarray){ print "Called and assigned to an array!\n"; } else{ print "Called and assigned to a scalar!\n"; } } my @a = foo(); my $b = foo(); foo();
This code produces the following output:
Called and assigned to an array! Called and assigned to a scalar! Called in void context!
user554546
source share