in reply to Dynamic Regular Expression

What have you tried? How did it fail? What specific detail are you having trouble with? See I know what I mean. Why don't you?. As a starting point you may find it helps to refactor your expression as:

use strict; use warnings; my @opts = qw(K1 ASC GEB N1); my $alts = join '|', @opts; my $re = qr{^(?:$alts)_(\w*\d*)$}; print "Matched $1\n" if 'GEB_S1' =~ $re;
Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Replies are listed 'Best First'.
Re^2: Dynamic Regular Expression
by Pratikh (Initiate) on Jan 06, 2021 at 15:56 UTC
    Thank you for the code snippet and I have added it to my main program and it is working as expected. Thank you for your help.