Deleting one HTML table but not another using PERL regex substitution
===

I'm still learning PERL so any help you could offer would be greatly appreciated.  I'm sure there is a simple answer to the problem I am looking at, but I'm not sure I can figure it out. Thanks in advance for your help!

I have txt file with a bunch of HTML code in it. There are a number of HTML tables that I want to remove. However, there are a couple that I want to keep.  These tables, the keepers, have specific words in them. 

Lets say $txt represents the text document

    $txt = "<TABLE> The brown dog runs </TABLE> 
            Here is another animal 
            <TABLE> The black cat walks </TABLE> 
            Here is another animal
            <TABLE> The Orange snake slithers </TABLE> 
            Here is another animal   
            <TABLE> Green lizard crawls </TABLE> 
            Here is another animal 
            <TABLE> The brown bird flys </TABLE> 
            Here is another animal          
            <TABLE> The green duck flys </TABLE> 
            Here is another animal";

I want to keep any table that has a brown animal flying animal. I don't want to keep any of the other tables.  (I want to keep the 1st, 5th and 6th tables and get rid of the rest).  So keep the table if it has the word brown or if it has the word flys, delete the table if it doesn't. 

I have used the following regular expression to cut out tables in other cases, but this will remove all tables.

    $txt =~ s{(<Table>.*?)(</Table>)}{table_was_here}ismog;

How could i modify this code to keep tables that contain certain text strings?

Thanks again!