#!/usr/bin/perl
use strict;
use warnings;
my $html = q|
<html>
<head>
<style>
.classname{
color: red;
}
</style>
</head>
<body>
classname will have a color property.
</body>
</html>
|;
$html=~s/classname/NEW/g;
print $html;
classname
这在两个地方都替换了。如何将替换仅限于内容<body>
?我希望看到它使用HTML::Parser
or完成HTML::TreeBuilder
。