It looks like you're just trying to extract the tags from the document. The following should work:
use strict; use warnings;
read(DATA, $_, 1024);
print join "\n", m/<.*?>/g;
__DATA__
Once <a href="foo.html">upon</a> a time there was a
<font color="#FF0000">CODE <b>RED</b></font> situation.
EDIT: As per
Crian's comment, the above should be
print join "\n", m/<.*?>/sg; instead.
Or a line by line version, if you're working with large files:
use strict; use warnings;
while (<DATA>) {
print $&."\n" while m/<.*?>/g;
}
__DATA__
Once <a href="foo.html">upon</a> a time there was a
<font color="#FF0000">CODE <b>RED</b></font> situation.
This is not really a robust method, however, and you're probably better off using a library unless your needs are simple and you're sure the tags are formatted properly.