in reply to not able to replace the element in the middle of the string
$a=~ s/^aa$/ee/
Do a bit research what ^ and $ mean in the context of a regular expression. Then it will become clear why your replacement won't work.
Happy learning! Rata
PS.: a good start is here: planetscapes collection
In Section
Seekers of Perl Wisdom