diff --git a/build/tools/build_html.pl b/build/tools/build_html.pl
index 592c2e8a..80f22ddf 100755
--- a/build/tools/build_html.pl
+++ b/build/tools/build_html.pl
@@ -13,16 +13,25 @@
my @chapters = get_chapter_list();
my $anchors = get_anchors(@chapters);
+# start position of a link in the scratchpad
+my $link_pos;
+
+sub Pod::PseudoPod::HTML::start_L
+{
+ my $self = shift;
+ $link_pos = length($self->{scratch});
+}
+
sub Pod::PseudoPod::HTML::end_L
{
my $self = shift;
- if ($self->{scratch} =~ s/\b(\w+)$//)
- {
- my $link = $1;
- die "Unknown link $link\n" unless exists $anchors->{$link};
- $self->{scratch} .= '"
- . $anchors->{$link}[1] . '';
- }
+ my $link = substr($self->{scratch}, $link_pos);
+
+ die "Unknown link $link\n" unless exists $anchors->{$link};
+
+ substr($self->{scratch}, $link_pos, length($link),
+ '"
+ . $anchors->{$link}[1] . '');
}
for my $chapter (@chapters)