in reply to Why doesn't non-greediness work?

To explain this requires an understanding of the regex engine and what it is attempting to do. Basically, what you are doing can be simplified to the following:
my $body = 'img wink img smiley'; $body =~ s/img.+?smiley/:)/; # $body now contains just :)
Non greediness does not work backwards, only forwards. The substitution is looking for img (something non-greedy) smiley. The non-greedy ? merely means that the regex engine starts looking for the smallest possible match first, not the largest. Without the ? the largest string matched happens first.

Thus starting from the first img, it DOES find a match, hence it has no reason to backtrack, and gobbles the whole string.

What you want is something like this:

$body =~ s/<img([^>]+?)="Smiley">/:)/g; $body =~ s/<img([^>]+?)="Wink">/;)/g;
only looking for non '>' characters in your intervening text.