my $html = get('http://use.perl.org'); my $tag = ''; # or '<' . shift . '>' or ... my $count = 0; $html =~ s/$tag/ '<' . ++$count . ">$tag" /ge;