Perl:Use of array elements in pattern matching

I need to use array elements while pattern matching.

@myarr = (ELEM1, ELEM2, ELEM3);

following is the statement which I am using in my code. Basically I want to replace the ELEM1/2/3 with other thing which is mentioned as REPL here.

if (condition) {
s/(ELEM1|ELEM2|ELEM3): REPL: /;
}

I need a generic code instead of hardcoding the array elements inside the code since array elements are not known & may vary.

Thanks in advance.

you can match on the varnames:

my ($var1, $var2, $var3) = @myarr;
if (condition)
{
my $replacement =~ s/(${var1}|${var2}|${var3})/REPL/;
}

Try this:
if (condition)
{
my $regex = sprintf('(%s)', join '|' @myarr);
my $replacement =~ s/$regex/REPL/;
}

Thanks pludi. it works !!