# prepare the sql once my $sth = $dbh->prepare(q/select column1 from mytable where column2 = ?/); # while(something) { # assuming only one column and one row are returned $sth->execute($my_key_into_table); my ($column1) = $sth->fetchrow; } #### my $hashref = $dbh->selectall_hashref(q/select column1,key_column from mytable/, 'key_column');