#!/usr/bin/perl use strict; use warnings; show_size(); { my @var=(0..1000000); show_size(); } show_size(); exit(0); sub show_size { local $/; open(my $pfh, '<', "/proc/$$/status") || die $!; my $size = <$pfh> =~ /VmSize:\s+(\d+)/ ? $1 : 'unknown'; close($pfh); print "Process size: $size\n"; } # Output is # Process size: 49956 # Process size: 53864 # Process size: 53864 #### #!/usr/bin/perl use strict; use warnings; show_size(); { my @var=(0..1000000); show_size(); undef @var; } show_size(); exit(0); sub show_size { local $/; open(my $pfh, '<', "/proc/$$/status") || die $!; my $size = <$pfh> =~ /VmSize:\s+(\d+)/ ? $1 : 'unknown'; close($pfh); print "Process size: $size\n"; undef $pfh; undef $size; } # Output is # Process size: 49660 # Process size: 53568 # Process size: 49660