$_ = 'foo bar baz burk | gah'; my @words; /(?:(\w+)\s+(?{push @words => $1}))*/; # Not backtracking safe! See below. # Submatches are in @words now.