use strict; use warnings; foreach (''. 'New index', 'New index') { if (/(?:)? ((?:(?!<\/a>).)*) <\/a>/six) { print "Matched!\tImg=", ($1 ? $1 : 'None'), "\tLink: $2\t Link Text: $3\n"; } }