#!/usr/bin/perl use strict; use warnings; use Data::Dumper; # a cool core module # that dumps any structure my $href = a1(); #hash reference returned from sub print "v1=$href->{'v1'}\n"; #dot operator not needed print Dumper $href; a2($href); print Dumper $href; exit(0); sub a1 { my %hash; $hash{v1} = 10; $hash{v2} = 20; return \%hash; # %hash memory will "live" due to # reference counting } sub a2 { my ($href) = @_; $href -> {v1} = 30; #quotes are ok but not needed $href -> {'v2'} = 40; return; } __END__ v1=10 $VAR1 = { 'v2' => 20, 'v1' => 10 }; $VAR1 = { 'v2' => 40, 'v1' => 30 };