my $str = "abc {{xyz} abc} {xyz} {abc} {{xyz}} abc"; while ($str =~ /(\{(?:(?1)|[^{}]*+)++\})|[^{}\s]++/g) { print "$&\n"}
Standard input is empty
abc {{xyz} abc} {xyz} {abc} {{xyz}} abc
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!