while (my @row = $sth->fetchrow()) { $names{$row[0]}{$row[1]} = [$row[2],$row[3],$row[4],$row[5]]; } #### while (my @row = $sth->fetchrow()) { push @{ $names{ $fields[0] }{ $fields[1] } }, [ @fields[2 .. 5] ]; } #### use strict; use warnings; my %names = ( X => { A => [ [ qw( Gay Deceiver Head Honcho ) ], [ qw( Chill Blaine Corporate Pawn ) ], [ qw( Tuesday Next Government Agent ) ], [ qw( Harry Hoo Freelance PI ) ], ], B => [ [ qw( Wiley Coyote Acme Addict ) ], [ qw( Gay Divorcee Party Animal ) ], ], }, Y => { A => [ [ qw( Maxwell Smart Agent 86 ) ], ], }, ); for my $key1 (keys %names) { for my $key2 (keys %{ $names{$key1} }) { for my $row_ref (@{ $names{$key1}{$key2} }) { if ($row_ref->[0] eq 'Gay') { print 'Found: ', $row_ref->[0], ' ', $row_ref->[1], "\n"; } } } } #### 14:21 >perl 1541_SoPW.pl Found: Gay Divorcee Found: Gay Deceiver 14:22 > #### my $sth = $dbh->prepare("SELECT * FROM employees WHERE firstname = 'Gay'" );