The data tbl_Customer ============ CustomerID_PK INT CustomerName VARCHAR CustomerType INT The Problem: I need to group the data returned by CustomerType and generate xml from this grouped data. The original query that returns the data is complex and does not sort the CustomerType column. My solution: I would get a reference to the whole recordset and create a hash that keys on CustomerType. The values for this has would be a concatenated string of references to the rows of data I would need to refer to later. Here is what I tried. #!/usr/bin/perl use strict; use DBI; my $dbh = DBI->connect("DSN Connection"); my $array_ref = $dbh->selectall_arrayref(q("Stored Procedure")); my %groups = (); foreach my $row (@$array_ref) { $groups{@$row[2]} = $groups{@$row[2]} . $row . "|"; } my @ref_values; my $value; my $key; while (($key, $value) = each(%groups) { @ref_values = split(/|/, $value); foreach my $row (@ref_values) { # I have tried many things here to try and use the reference to the array. # This is where I need help to get the data from my reference and generate # the xml string. Any suggestions?! } } JF ===== Regards, James Fisher __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/