my @lines = ("a 1 2", "b 3 4 5 6", "c 7 8 9"); foreach (@lines) { # you can't match multiple times starting at ^! my @list = m/(\s+\d+)/g; # no last + print @list, "\n"; }