my %has; my $query ="select * from table name "; my $exe = $dbh->prepare($query); $exe->execute(); while(my $data = $exe->fetchrow_hashref){ $has{$data->{firstattribute}}=$data->{secondattribute}; }