$line = 'Iteration {Applied Field} A {Total Energy} Mx F G {Third test line}'; print "$&\n" while $line=~s/(?<={)[\w\s]+(?=})|\w+//; Iteration Applied Field A Total Energy Mx F G Third test line