Thank you, Jim.
But then I need to call "sed -f .." in the perl script, and pass the perl variables to the sed script. It seems to complicate the problem.
I've found out that might be a concatenation problem in my system function. I rewrited it like this :
system('sed -e "/insert/ i\\'.$newline.'" <sed1.txt >sed2.txt');
And it works.
Now I have a new problem. It wouldn't let me use "+" for the regular expression. For example,
system('sed -e "/insert+/ i\\'.$newline.'" <sed1.txt >sed2.txt');
It fails to match "inserttt".
But with "*", it works well.
Basically, I want to have my perl script call the sed command to search for the string in subscript 0 of the 'test' array and replace it with subscript 1 of the 'test' array. I tried hi_ryo's method, but it didn't work in my case.