in reply to Hash from mySQL

From the way you have populated %ref, it looks like a simple hash whose key is $port and value is a (host)name.

In that case, the following code:

{foreach $port (@{$ref{$key}{'port'}})
is trying to treat %ref as a HOH. IMHO, the outer loop should look like:
for my $port (keys %ref){ my $host = $ref{$port}; # Process the $host/$port combo ...

             I hope life isn't a big joke, because I don't get it.
                   -SNL