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 !!!"; }