while($line = <DATA>){

@valid_entities= ('<a>','<abbr>','<acronym>','<br>');
my %htmlenties = map { $_ =>1 } @valid_entities;
#$line =~ s/(<\w*?>(?![^<\w*?>]*<\/\w*?>))/$1/g;
#$line =~ s/<\w*>(?![^<\/\w*>]*>)/&lt;/g;
$line =~  s/(<(\w*?)>)/exists $htmlenties{$1} ? $1 : defined ($2) ? "&lt;$2&gt;" : "&lt;"/eg;
print $line;

<helloe>How r u <a></a>
<hi>How r u </hi><et,-2><><br/>

How to convert character '<' to '&lt;'and '>' to &gt; for all the characters which is not present in the array and only if it doesnot have a closing end tag.In the above example,

the output should look like

&lt;helloe&gt;How r u <a></a>
<hi>How r u </hi>&lt;et,-2&gt;&lt;&gt;<br/>