$sting =~ m{\b # word boundary ( \S+ # word before '(' \s* # spaces if any \( [^\)]+ # '(' inside of ')' \) ) [^\)]* # some not ')' chars if any $ # end of string ancor }x; $result = $1;