sub xyz { my ($tgs) = @_; return eval <<"END_OF_SUB_XYZ"; my %Test_hash_$tgs; my \$other = "Why did I do this?"; print "\$other Now I have to escape so many things.\n"; END_OF_SUB_XYZ ; } #### sub xyz { my ($tgs) = @_; my $hash_name = "Test_Hash_$tgs"; my %{$hash_name}; } #### sub xyz { my ($tgs) = @_; my %Test_hash{$tgs} = {}; # use $Test_hash{$tgs}{foo}, etc. }