- or download this
$ perl -lE '
my ($haystack,$needle)=@ARGV;
...
found at 0
found at 6
found at 13
- or download this
$ perl -lE '
my ($haystack,$needle,$new)=@ARGV;
...
say "new string: $haystack"
' abcsdfabcasegabc abc foo
new string: foosdffooasegfoo
- or download this
s/\Q$str\E/$new/g; # since \E is at the end, it's not really required.