Not sure if you can do it automatically or not, but I can tell you how I would do it with thunderbird.
t-bird has a search box, where you can select the search criteria. The search criteria defaults to Subject or Sender, which is usually sufficient. You can copy and paste the subject into the search box, and that limits the display to only those messages that meet the search criteria. Make sure the right messages are there (and only those messages you want to delete), then select all in the right window, and press the Delete button.
I know that's probably not exactly what you were asking, but I don't know of any automatic way to do what you want. Also, this method works no matter what type of email server you are using.
-David