I'm not terribly familiar with perl, but assuming the s/... works like normal sed: I would guess it's matching the entire 'ram' element @actiontext[2], but you're only replacing the 'ram' part with $2 (or actually nothing, for that match) - leaving the remainder of that element to be put into @action[1].
Here you are grepping the array element which contain string 'delivered to governor on' or 'ram' and do some substitution. So you wont get the array elements which dont have the matching string.
I think, you need all the array elements and do the substitition in some of the array elements.
my @actionText = ("delivered to governor on 21/23/3345" , "deliver jllj" , "ram 2345/43");
my @action = map{$_=~ s/delivered to governor on |ram//;$_;} @actionText;
print "@action\n";
This is what you are looking for ..?
It will remove the string 'delivered to governor on ' or 'ram' before assigning all the array elements from @actionText to @action.
you misunderstood my question, i know the difference between map and grep.
i wanted to substitute "delivered to governor on 21/23/3345" with 21/23/3354 and "ram 2345/43" with "2345/43", so i substituted with $2 in delivered to governor on 21/23/3345, but the string when matched ram... how it is substituting "2345/43" even though i dint group that in regular expression.
Your question should be - why is "21/23/3345" showing up in the array @action.
The string " 2345/43" has all the more reason to be there because you substituted "ram" by nothing, thereby chopping it off.
You are chopping the texts 'delivered to governor on ' or 'ram ' with $2. Here $2 deosn't have any value hence it substitute with empty string.
durden_tyler has been stated above clearly. Thanks mate
Thanks for your reply, i missed that.
I have one more question. i have code like below , i need to get the text between certain patterns , suppose i have below array