sub foo { my $m = shift; my @array = ($m*1, $m*2, $m*3); return \@array; } my $x = foo(2); my $y = foo(3); use Data::Dump; dd $x; # [2, 4, 6] dd $y; # [3, 6, 9] $x = undef; # *now* the memory for that array is freed