use strict; my $str = "1 2 3 4 5 6 7 8 9 10"; my (@a, @b); while($str =~ m/(\d+) (\d+)/g) { push @a, $1; push @b, $2; } print "\@a = @a\n"; print "\@b = @b\n"; #### @a = 1 3 5 7 9 @b = 2 4 6 8 10