如何从特定位置的字符串中删除字符?

jav*_*irl 4 perl substring

我有变量$pos,$toRemove$line.我想从这个字符串中删除$toRemove位置$pos.

$line = "Hello kitty how are you kitty kitty nice kitty";
$toRemove = "kitty";
$pos = 30; # the 3rd 'kitty'
Run Code Online (Sandbox Code Playgroud)

我想检查从位置30是否有字符串kitty,我想要删除这一个.

你能给我一个解决方案吗?我可以使用很多循环和变量来做它但它看起来很奇怪并且工作得很慢.

Cyb*_*m0n 6

if (substr($line, $pos, length($toRemove)) eq $toRemove) {
    substr($line, $pos, length($toRemove)) = "";
}
Run Code Online (Sandbox Code Playgroud)