The solution I discovered is this...
$contents =~ s/(<IMG\s.*?>)/&addalt($1)/sige;
$contents =~ s!\>alt=\"\"! alt=\"\"\>!sig;
print $contents;
sub addalt {
my $returned=shift;
if ($returned!~m/\salt/){
$returned=$returned.'alt=""';
}
return $returned;
}
The key I discovered was the "e" switch on the regex. |