use strict; use warnings; undef $/; $_ = ; # slurp print "1: $1 - $2\n" while /<\s*(?!a\b|img\b)(\w+)\b(.*?)\s*>/g; print "2: $1 - $2\n" while /<\s*(?!a|img)(\w+)(.*?)\s*>/g; my %absent = ( a=>1, img =>1 ); while (/<\s*(\w+)(.*?)\s*>/g) { print "3: $1 - $2\n" unless $absent{$1}; } while (/<\s*(\w+)\b(??{ $absent{$1} ? '^' : '' })(.*?)\s*>/g) { print "4: $1 - $2\n"; } __DATA__ #### 1: table - style="" 1: anchor - 1: tr - width=100 2: table - style="" 2: tr - width=100 3: table - style="" 3: anchor - 3: tr - width=100 4: table - style="" 4: anchor - 4: tr - width=100