$a=join " ",0..7; sub fold (&) { my @a; push @a, [$1,$2] while $_[0]->(); @a}; print Dumper fold { $a =~/(\w) (\w)/g };