use strict;
use warnings;
use HTML::Parser;
use HTML::Entities;
my $html = join '', ;
my $p = HTML::Parser->new(
default_h => [ sub { print shift }, 'text' ],
comment_h => [""],
start_h => [ \&start, 'tag,attr,attrseq,text' ]
);
$p->parse($html);
sub start {
my ( $tag, $attr, $attrseq, $text ) = @_;
unless ( exists $attr->{href} ) {
print $text;
}
else {
$attr->{href} = "#";
print "<$tag";
print " $_=\"", encode_entities( $attr->{$_} ), '"' for (@$attrseq);
print ">";
}
}
__DATA__
title
link
some text and more