The key I discovered was the "e" switch on the regex.$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; }
In reply to Re^2: Conditional regex
by Anonymous Monk
in thread Conditional regex
by sherab
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |