NPS
NPS

Reputation: 6355

Regex pattern concatenation

Is it possible to somehow concatenate this:

my $ pattern1 = qr/^/;

with this:

my $ pattern2 = qr/ABC/

so I get (the value of) this?

qr/^ABC/

The syntax could be different, I just want to achieve this result.

Upvotes: 0

Views: 3332

Answers (1)

choroba
choroba

Reputation: 242038

You can concatenate regular expressions easily:

say /$pattern1$pattern2/ for 'ABC', 'XABC';

To increase readability, you can use the /x modifier and add a space:

say / $pattern1 $pattern2 /x for qw( ABC XABC );

Note that scalars are usually written without the space after the $ sigil.

Upvotes: 6

Related Questions