my @Val = qw(aaa bbb ccc); my $str = 'TESTDATA_BETA$Val[1]_DEFL$Val[2].$Val[0]'; if ($str =~ s/(\$[^]]+\])/$1/gee) { print "$str\n"; }