Delete all elements without linked boards

Is there a way to automatically delete all elements that are not linked to a board/element?
I need this because in a board as soon as a status changes the element is deleted and I also want to delete the elements on the linked boards that were linked to this element.