Under the blind assumption that your data won't be changing too much or becomes 'faulty' (otherwise you'd be using a
parser right?) then something like this ought do
my $re = qr{
(?: <img \s+ .*? src=" ([^"]+) " .*? > )?
<a \s+ .*? href=" ([^"]+) " .*? >
}x;
$in =
'<td><img src="foo.jpg"><a href="index3.html">New index</a></td>';
my($href, $img) = grep defined, reverse $in =~ $re;
print "href - $href\nimg - $img\n";
$in = '<td><a href="index3.html">New index</a></td>';
($href, $img) = grep defined, reverse $in =~ $re;
print "href - $href\nimg - $img\n";
__output__
href - index3.html
img - foo.jpg
href - index3.html
img -
See.
perlre for more info.
HTH
_________
broquaint