use DBI; use strict; # declare holder for our record set and some sample sql my @results; my $sql = "select * from msazip where zip = 60604"; # connect to sql server my $dbh = DBI->connect("dbi:ODBC:mysql", "username", "pass", { RaiseError=>1 } ) or die "$!"; # prepare and send the query my $sth = $dbh->prepare( $sql ) or die "$!"; $sth->execute(); # get the column names if you don't know them already my @col_names = @{ $sth->{NAME}}; # build an array of hashrefs so we can preserve order of record set while( my $hr = $sth->fetchrow_hashref ){ push @results, $hr; } # now use them - in this case just print each row # $rs->{'col_name'} or $results[0]->{'col_name'} foreach my $rs (@results ){ print ( sprintf "%-15s", $rs->{$_} ), " " foreach @col_names; print "\n"; }