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}}) { ... }

-sauoq
"My two cents aren't worth a dime.";