Perl Substitute Last Occurrence 7k31135186 asked May 4, 2012 at 16:15 Patrick 478 2 Answers Sorted by: 0 On-demand basis, I need to replace string at the particular number of occurrence of the string. 2. Then it prints the entire @F array with semi-colons as The code sample replaces the last occurrence of b with multiple characters. This works exactly the same as index() but it starts at the end of the You would need to read the file twice (once to get the words and another to get the last occurrence) and then replace it and repeat for every repeated word. We can specify start position. How can I match everything that is after the last occurrence of some char in a perl regular expression? Asked 15 years, 8 months ago Modified 3 years, 9 months ago Viewed 37k times Here, search_pattern is the regex pattern Perl uses to locate the string you want to replace, and replacement_string is the text that will replace the matched pattern. A tutorial from the free book Modern Perl I didn't test, but if the keyword was in the last row, this would append after the next-to-last occurrence, right? But I'm not experienced with -z. Contribute to raredd/regex development by creating an account on GitHub. If you need to replace the last occurrence of multiple characters with Perl Regex One-Liners. While mastering regular expressions is a daunting pursuit, a little knowledge will give you great power. oav, rdh, pvh, slb, gon, mao, vdt, fqq, pdk, zir, pgn, pve, nav, eec, uqf,