in reply to Two Regex Searches Simultaneously (on One Line)

Consider:
use strict; use warnings; use 5.012; use Data::Dumper; my $s1 = '45 20 00 00 00 03 00'; my $s2 = '40 20 00 00 00 00 00'; while ((my @a = $s1 =~ /(\d{2})/g) && (my @b = $s2 =~ /(\d{2})/g)){ say "found $a[0] and $b[0] !!!"; say Dumper(\@a, \@b); }
A regex in list context will give you all matches at once.

Next time the loop comes around, it starts all over again as it has exhausted its matching and resets.

This code will do what you want:

use strict; use warnings; use 5.012; use Data::Dumper; use List::MoreUtils qw/each_array/; my $s1 = '45 20 00 00 00 03 00'; my $s2 = '40 20 00 00 00 00 00'; my @first = $s1 =~ /(\d{2})/g; my @second = $s2 =~ /(\d{2})/g; my $ea = each_array(@first, @second); while (my ($first, $second) = $ea->()){ say "found $first and $second !!!"; }

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James