Используйте надлежащий анализатор, такие как HTML::TokeParser::Simple:
#!/usr/bin/env perl
use strict; use warnings;
use HTML::TokeParser::Simple;
my $parser = HTML::TokeParser::Simple->new(handle => \*DATA);
while (my $token = $parser->get_token('script')) {
if ($token->is_tag('script')
and defined(my $src = $token->get_attr('src'))) {
$src =~ m{^https?://}
or $token->set_attr('src', "[perl]texthere[/perl]$src");
}
print $token->as_is;
}
__DATA__
<script src="/js/text.text.js/"></script>
And at the same time, ignore scrs that begin with http, as such:
<script src="https://websitewebsitewebsite"></script>
Выход:
<script src="[perl]texthere[/perl]/js/text.text.js/"></script>
And at the same time, ignore scrs that begin with http, as such:
<script src="https://websitewebsitewebsite"></script>
Возможный дубликат http://stackoverflow.com/questions/11247071 – dgw