# make the query $array_ref = $dbh->selectall_arrayref("SELECT name,height,width,date FROM mydatabase"); # drop it all into a hash named %DB foreach $i ($$array_ref) { if($Sort == "byname") { $DB{ $$i[0] } = [ $$i[1],$$i[2],$$i[3] ]; } elsif($Sort == "bydate") { $DB{ $$i[3] } = [ $$i[1],$$i[2],$$i[0] ]; } }