in reply to Edit in place (part2)
Dunno, but you could try replacing s/foo/$myvar/i; with substr($_, $-[0], $+[0] - $-[0], $myvar) if /foo/i;