if (m{\[table\] # Match [table] ([^[]* (?:\[(?!/table\]) [^[]*)*) # Match a string not containing [/table] \[/table\] # Match [/table] }x) {print $1}