in reply to fetching data from MySQL

You should read up on DBI, and select a function that returns the data you need in the order you need it. For example:

#!/usr/bin/perl -w use strict; use DBI; $|++; my $user = "username"; my $pass = "password"; my $dbnm = "database"; my $table = "table"; my $dbh = DBI->connect("DBI:mysql:$dbnm", $user, $pass); my $ret = $dbh->selectcol_arrayref("select line_n, word from $table", +{ Columns => [ 1, 2 ] }); $dbh->disconnect; my %seen; my @list = @$ret; while (@list){ my $line_n = shift @list; my $word = shift @list; print $seen{$line_n}++ ? " " : "\n$line_n: "; print $word; }

-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells