You found comma-operator
From perldoc perlop:
Binary "," is a comma operator. In a scalar context, it evaluates the left argument, discards that value, then evaluates its right argument and returns that value.
So, this is actually considered one statement:
my $bar = shift or die "Missing bar", my @items = ();
Perl evaluates the LHS and discards the result, since this assignment, which does not actually cancel anything, is still assigned $bar , then it evaluates the RHS and returns that value. It is important to note that this means that @items initialized as a static lexical variable in your sub-populator, but remains static in all foo() calls. Similar to how state works.
At this point in the routine, you assigned 1 to $bar . Next line:
push @items, $bar;
Perl clicks $bar on the static lexical variable @items . The following statement returns a list of one item 1 .
Subsequent calls to foo continue to add elements to the @items array and return these elements. This is why you see more than 1 from subroutine calls.
source share