Is it possible to use corresponding or operators (|) in the match and substitution strings of a regex substitution, such that a list of different possible matches is replaced by a corresponding list of different substitution strings? For instance,
perl -e '$str="word1"; $str=~s/1/2/; print $str."\n"'
word2
perl -e '$str="word3"; $str=~s/3/4/; print $str."\n"'
word4
perl -e '$str="word1"; $str=~s/1|3/2|4/; print $str."\n"'
word2 (actual output: word2|4)
perl -e '$str="word3"; $str=~s/1|3/2|4/; print $str."\n"'
word4 (actual output: word2|4)
The last two statements give fictitious (desired) output (the real output is shown in parentheses).
Credits go to user mu is too short.
Regular expression substitution using multiple matched input patterns and output strings is achieved in Matlab as shown in the following example.