in reply to substitute within elements of array
G'day Dr Manhattan,
You say "... ending with ,|?|! ..." but your regex (s/(\.|\?|\!)$//) isn't removing commas. Is that the bit that isn't working? You really need to show your input and output: "it does not work" is an entirely inadequate error report.
I think you'd be better off with a single character class ([?!,]) than an alternation with all those escaped characters:
$ perl -Mstrict -Mwarnings -E ' my @words = ("what?", "what!", "what,"); say for map { s/[?!,]$//; $_ } @words; ' what what what
-- Ken
|
|---|