@lists = check_id($id); print "In: @lists"; sub check_id { $ids = shift; $sthm = $dbh->prepare("SELECT name,parent FROM category WHERE id = '$ids'"); $sthm->execute or die $dbh->errstr; ($name,$parent) = $sthm->fetchrow_array; push(@info, $name); if($parent ne "0") { $line = check_id($parent); push(@info, $line); } return(@info); }