http://www.perlmonks.org?node_id=475100


in reply to Re: Replacing a specfied instance of a pattern in a string
in thread Replacing a specfied instance of a pattern in a string

or to pass the index in use:

use warnings; use strict; my $foo = 'Fsih my test variable is fsihd or is it gfsih or gfsihd fsi +h'; my $i = 2; # Replace the 3rd $foo =~ s/((?:fsih.*?){$i})fsih/$1fish/i or warn "Not found"; print "Foo = $foo\n";

Perl is Huffman encoded by design.