Here's a marginally more clever version of your solution, which relies on the placeholder capabilities of a /g search. I mention it because I think it's a tiny bit more readable than the version you wrote. But ... you know ... personal preference and all that.
use strict; use warnings; my $test_string = "3 xyz"; # Start a global search # It looks like the expected pattern includes a space. Let's put it he +re. if ( $test_string =~ m/^(\d+) /g ) { my $length = $1; # Pick up the search where our first match left off. if ( $test_string =~ m/\G(.{$length})/ ) { my $result = $1; # Do stuff with $result ... } }
In reply to Re^2: Backref in a regex quantifier
by webfiend
in thread Backref in a regex quantifier
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |