my $array_ref = $dbh->selectcol_arrayref("SELECT color, 1 FROM color", { Columns => [1,2] } ); my %colors = @{ $array_ref }; # Now rewrite the loop above along the lines of- # for my $color ( sort keys %colors )