$x="ab[x=1 y=2 z=5] cd [z=4] ef"; @y = ($x=~/\[(.*?)\]/g) ; print join ", ", ( split /[\[\]= ]+/, ( join " ", @y ) ) ;