Hi everybody,

I was wondering, if it is possible to use backreferences in the pattern
repetition bracket operator.

Consider the following string:

my $string = "5 abcdefghijklmn";

The number five at the beginning of the string means, that I want to
extract first five characters from the latter part of the string. I
tried the following code, but it doesn`t work:

$string =~ s/(\d+)\s+(.{\g1})//;
print "extracted: $1 $2\n";

The desired output would be:

extracted: 5 abcde

It seems, that it is not possible to use backreferences within the
bracket operator (or am I doing something wrong?).

Is there other solution to my problem.

Than you in advance for your time

Regards

Honza Mach
Cesnet

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to