# x not defined print "X not defiined:\t ",scalar @x,"\n" if (!defined(@x)); # given an empty list @x = x(); print "X empty list:\t ",scalar @x,"\n"; @x = (1,2,3); # x given a populated list @x = x(); print "X populated:\t ",scalar @x,"\n"; sub x () { return @x if defined(@x) and warn "\@x was already defined"; return @x if (scalar @x==0) and warn "\@x is 0"; return wantarray ? () : undef; } Output: X not defiined: 0 @x is 0 at wa.pl line 14. X empty list: 0 @x was already defined at wa.pl line 13. X populated: 3