in reply to I know this code could be better...

I don't like code that updates a global value when it's not necessary. I like to be able to see, easily, where information comes from. This results in more maintainable code (you know where to look when something goes wrong).

That said, I'd rewrite your populate_hash to return a hash, or better still (for performance reasons), a reference to a hash. You then set %top_level to the return value of that subroutine. It's as easy as having the first line of the sub be:

sub populate_hash { my %hash; # populate hash \%hash; }

Note this returns a reference to a hash, which means you have to get a little fancier when you call the subroutine (or modify your code to work with the hash reference, but I foresee less hair-pulling if you keep the hash).

my %top_level = % { populate_hash() };

The "extra" %{} parts tell the interpreter that it should set %top_level to the hash which the return value of populate_hash refers to.

I swear that makes sense in some language. =) For more on references, see perldoc perlref and perldoc perlreftut. Once you get the hang of working in references, you see all sorts of new solutions to data-manglement.

HTH

perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'