Matthew Glidden Matthew Glidden - 6 months ago 4x
Perl Question

How do I fix the perl syntax error "missing right curly or square bracket" using VIM?

Compiling (or executing) a perl program with unmatched array braces ("[ ]") or scope brackets ("{ }") causes the "missing right curly or square bracket" syntax error. Perl often reports the source as your last code line ("at EOF"), which could be far removed from the actual missing piece.

Example perl error message:

Missing right curly or square bracket at ./ line 100, at end of line
syntax error at ./ line 100, at EOF
Execution of ./ aborted due to compilation errors.

How do vi or Vi IMproved (VIM) users troubleshoot this error message? I've added an answer with some VIM enhancements. Please add your own ideas, practices, or vi plugins.

NOTE: Original question posted with VIM version that didn't highlight perl braces and brackets. Many newer versions do this; see for more info.


How to troubleshoot this error right now:

  1. In VIM, pick an opening {, [, or ( symbol. The % command jumps between matching { }, [ ], and ( ) pairs. Mismatches will jump to an unexpected location.

  2. Install perltidy, run it, and look for oddly indented code blocks.

How to prevent future errors:

  1. StackOverflow question 719476 shows how to modify VIM brace/bracket syntax coloring for braces/brackets. (Some versions don't do this by default.)

  2. Karl Guertin's AutoClose plugin auto-matches [, (, {, ", ' symbols when typed.

  3. perltidy script reformats perl for readability, which can expose mismatched symbols.

  4. User a paid nerd said: "Use perltidy within VIM editor with nmap."

    nmap \g mt:%!perltidy<CR>'t

  5. Use consistent {} matching indentation (general tip, not specific to this perl error).


sub foo {


sub bar