Why do I get the first capture group only?
问题 (https://stackoverflow.com/a/2304626/6607497 and https://stackoverflow.com/a/37004214/6607497 did not help me) Analyzing a problem with /proc/stat in Linux I started to write a small utility, but I can't get the capture groups the way I wanted. Here is the code: #!/usr/bin/perl use strict; use warnings; if (open(my $fh, '<', my $file = '/proc/stat')) { while (<$fh>) { if (my ($cpu, @vals) = /^cpu(\d*)(?:\s+(\d+))+$/) { print "$cpu $#vals\n"; } } close($fh); } else { die "$file: $!\n"; } For