sub foo { my $num = shift; my @arr = (42)x$num; return @arr; } my $x = foo(1); print $x; #### return wantarray ? @arr : $arr[0];