print "Content-type: application/vnd.ms-excel\n\n"; print join("\t", @cols) . "\n"; foreach my $row ( @rows ){ print join("\t", @$row) . "\n"; # if rows are array refs print join("\t", @{$row}{@cols} ) . "\n"; # if rows are hash refs }