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