USER: while ( $pointer = $sth->fetchrow_hashref ) { $username = $pointer->{'username'}; # Connect to jobs DB and get the entries that match the username # XXX Changed from != to =, and selecting only the count. $SQL2 = "SELECT count(*) FROM $jobstable" . " where username = '$username' and active = 'yes'"; &Do_SQL2; $pointer2 = $sth2->fetchrow_hashref; if ( $pointer2->{'count(*)'} > 0 ) { print "Skipping active user '$username'\n"; next USER; } $userdirectory = $rootpath . $username; print "Directory '$userdirectory' to be deleted\n"; File::Path::rmtree( $userdirectory ); }