Skip to content

Perl Conditional Replace Depending On Match

So, as I write patches for various awful build systems, one of the things I try to do is slim down the patch file and make it easier to read. Changing “foobar-1.orig” to just a and “foobar-1” to just b makes a difference. Rather than manually edit the patch file, I turn to my dear friend, the regex search-and-replace. But, it gets to be a bit tiring editing essentially the same regex twice to get nearly identical results.