my $select1 = "select distinct b.carrier, b.boxno, b.listno, b.shipno, b.custno from data1 b where b.custno = 160 order by b.listno "; my $sth = $dbhandle1->prepare($select1); $sth->execute(); print "carrier,boxno,listno,shipno,custno\n"; while (my $hash_ref = $sth->fetchrow_hashref) { print "$hash_ref->{carrier},"; print "$hash_ref->{boxno},"; print "$hash_ref->{listno},"; print "$hash_ref->{shipno},"; print "$hash_ref->{custno}\n"; }