in reply to Match last instance of pattern
If you're not that fortunate, you could use captures: s/(.*)<\/TABLE>/${1}REPLACE/