in reply to Suggestions for handling a complex set of data

Maybe a hash is the wrong structure.

You could use a hash of arrays

my %pats_hoa=(); while (my $row = $sth->fetchrow_hashref){ my $voucher = delete $row->{'Voucher_Number'}; my $proc_code = delete $row->{'Procedure_Code'}; push @{$pats_hoa{$voucher}{$proc_code}},$row; } for my $voucher (sort keys %pats_hoa){ for my $proc (sort keys %{$pats_hoa{$voucher}}){ for my $rec (@{$pats_hoa{$voucher}{$proc}}){ if ($rec->{Transaction_Type} eq '???'){ # do something; } } } }
poj