As
thezip says, it looks like your reference to the HoH is suspect - if
matrix is defined as
%matrix (some information that you've neglected to provide), the reference probably ought to be
$matrix{$key}->{$key2}.
A user level that continues to overstate my experience :-))