$ sed s/i/u/2 <<< fizzbizz fizzbuzz
Perl’s substitute operator comes from
sed and looks pretty much the same, but it can’t do this.
$ perl -pe 's/i/u/2' <<< fizzbizz Unknown regexp modifier "/2" at -e line 1, at end of line Execution of -e aborted due to compilation errors.
We’d have to do some awkward counting maneuver with an eval or something.
$ perl -pe 's/i/++$n - 2 ? "i" : "u"/ge' <<< fizzbizz fizzbuzz
I used to use
sed quite a bit, but since learning Perl I find I don’t have much use for them anymore. I miss
sed. But here’s one more reason not to let my
sed skills atrophy completely.