If I were doing this for real I would use /g as Corion suggests. However, for interest's sake, here is one way to construct the pattern without repetition in the code.
#!/usr/bin/env perl use strict; use warnings; my $x = "0.01 NaN 2.30 4.44"; my $r1 = join '\s+', ('([Na0-9\.\-\+]+)') x 4; print "r1 is '$r1'\n"; my ($d, $e, $f, $g) = ($x =~ m/$r1/); print qq($d, $e, $f, $g\n);
Note that you don't need all those backslashes so the inner character class can be shortened to just [Na0-9.+-] but it has no effect on the end result.
If this is an XY Problem, then perhaps if you explain what you are actually trying to do someone could suggest a better approach.
🦛
In reply to Re: Repeating a capture group pattern within a pattern
by hippo
in thread Repeating a capture group pattern within a pattern
by mldvx4
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |