sub getarticles { my $article = shift; my $query = qq(SELECT reply FROM replies WHERE article=$article ORDER BY reply); my $sth = $dbh->prepare($query); $sth->execute; $sth->rows or return 0; while (my $reply = $sth->fetchrow) { my $query = qq(SELECT timestamp, subject, author FROM article WHERE id=$reply); my $sth = $dbh->prepare($query); $sth->execute; my ($timestamp, $subject, $author) = $sth->fetchrow; $sth->finish; ( code to show the retrieved items as html, snipped ) $indent++; &getarticles($reply); $indent--; } $sth->finish; return; }