use DBI; my $db = DBI->connect("dbi:SQLite:dbname=/root/chess/icc/chartbot/chartbot.db", "", ""); $sth = $db->prepare ("SELECT COUNT(*) AS Anzahl, handle FROM channels where timestamp >= 1310478879 and channel = 1 GROUP BY handle ORDER BY Anzahl DESC LIMIT 5"); $sth->execute (); while (my @z = $sth->fetchrow_array ()) { $handle = $z[1]; $count = $z[0]; print "$handle ($count)\n"; }