Your code is just wrong for a variety of reasons. Excuse me if I don;t take the time to explain the problems. What you want to do if we stick we the same basic concept, is use a hash instead of trying to cobble together dynamic variable names , which is possible but is a very bad idea 999.9999 times out of a hundred. I don't recommend this but I am just trying to stick to your general concept. Use a hash to store the patterns you want to replace in the string with their associated value (%words in the code below).

I assume you are trying to do it this way because you are either a student learning perl or just need to use perl but never learned it and now are trying to hurry some code together using logic you might apply using a programming language you might know already but which does not translate well to perl. -------------------------------------------------

No, it will not replace the 1 in abc1. You can try that in the code I posted for you. A regexp only replaces the first search pattern unless you tell it to do more search and replace for the same pattern in the same string using the "g" modifier or other looping logic.

the first problem is that perl will interpolate the scalar variables $1, $3 and $5 in the double-quoted string and replace them with their stored values, and since they have no values the value of $dest_file1 is:

__abc

even if you use single quotes to kill the variable interpolation:

my $dest_file1 = '$1_$3_$5abc';

It still won't work, but for other reassons. -------------------------------------------------

Yes. I am aware of "g". I need to use this as 1 may be repeated in the file name . For.e.g. I amy have the file name as 1_2_3_1_abc1 . Here first two 1's should be repalced with the first field name. But the last one should remain. With modifier g, it would replace all 1with the value. Please advice. Is there any way can we use $ or some thing to distinguish.

Yes. I am aware of "g". I need to use this as 1 may be repeated in the file name . For.e.g. I amy have the file name as 1_2_3_1_abc1 . Here first two 1's should be repalced with the first field name. But the last one should remain. With modifier g, it would replace all 1with the value. Please advice. Is there any way can we use $ or some thing to distinguish.

You can seperate the process into two steps instead of trying to do it all in the regexp. Replace what you need in 1_2_3_1 and then append abc1 back to the string after doing all the paterrn search and replace. -------------------------------------------------

If the suggestion I have been able to give you still will not work for you try www.perlmonks.com or www.stackoverflow.com but try and define the nature of your problem better and include all pertinent information. Maybe some one else can come up with a solution for you based upon all the information.