@valid_entities= ('a','abbr','acronym','br');# remove tags my %htmlenties = map { $_ =>1 } @valid_entities; $line =~ s/ < # a tag open ( # begin capture group 1 \/? # an optional slash ( # begin capture group2 [^>]*? any number of characters that aren't closing tags ) # end capture 2 \/? # an optional slash (xhtml and all that) ) # end capture group 1 > # a closing tag /exists $htmlenties{$2} ? "<$1>" : defined ($1) ? "<$1>" : "<"/xeg;# different captures => different process