use strict; use warnings; my $plus; my $N; my $text = "abc123def"; my $text_match = qr/((\D+)(\d+))(?{ $plus = $+;$N = $^N })(\D+)/; $text =~ $text_match; print "$plus, $N\n"; $text_match = qr/(\D+)(\d+)(?{ $plus = $+;$N = $^N })(\D+)/; $text =~ $text_match; print "$plus, $N\n";