in reply to keys of hash of reference to hash
I think you want your second foreach to look more like:
foreach my $key (keys %{$matches->{$pid}}) { ... } [download]
-sauoq "My two cents aren't worth a dime.";