Perl Code Formatter
FormatEverything runs locally in your browser — nothing is uploaded
Indentation cleanup for Perl. Not bracket counting — this uses a real parser (tree-sitter) to build the syntax tree and decide from the grammar how deep each line goes. Why does that matter here especially? A bracket-counting approach cannot tell whether a `}` is in the code or inside a string or comment, and Perl is unusually full of that trap: `$h->{key}`, `"${name}"`, `q{...}`. One file containing `"}"` throws off every line after it, with nothing to indicate anything went wrong. With a syntax tree, block boundaries come from the parser. ⚠️ Only the leading whitespace of each line changes — not a character inside it. That constraint is deliberate: the worst failure for a formatter is not ugly output but breaking working code, which is worse than doing nothing. So there is no inline spacing cleanup, no reordering, no re-wrapping and no line removal. ⚠️ Heredoc bodies and POD directives are left entirely alone. Both are Perl-specific: a heredoc body is string content, so indenting it inserts spaces into your data (worse with `<<~`, where the relative indentation of the body lines *is* the meaning); and POD directives must start at column 0 — indent one and Perl stops treating it as POD, parses it as code, and errors out. No other language here needs this, which is why Perl handles it separately. Incomplete code still produces output instead of an error — that is how formatting while typing is supposed to work.
Features
- A real tree-sitter parse — indentation follows the grammar, not bracket counting
- Brackets inside strings, comments and `q{}` do not affect the structure
- Heredoc bodies and POD directives are never touched — a Perl-specific guard
- Only leading whitespace changes; not a character inside a line
- Indent with 2 spaces, 4 spaces or tabs
- Incomplete code still produces output instead of an error
- Syntax-highlighted output
- Runs entirely on your device — the code is never uploaded
How to use
- Paste the code into the left pane
- Pick an indent width
- Press Ctrl/⌘ + Enter or click Run
- Copy the result
FAQ
- How is this different from other online formatters?
- Most online formatters do text-level indentation: scan character by character, indent on `{`, dedent on `}`. They cannot tell whether a bracket is in the code or inside a string. This one uses a real parser: the code becomes a syntax tree first, and each line’s depth is decided by the grammar it belongs to. The cost is a Perl grammar file plus the parser runtime (about 4.4 MB together), downloaded only when you open this tool’s page. What you get in return is structure detection that does not guess.
- Are heredocs and POD ever changed?
- No — and this is a Perl-specific care. A heredoc body and POD directives (such as `=head1`) are left completely alone: a heredoc body is string content, so indenting it inserts spaces into your data, and POD directives must start at column 0 — indent one and Perl stops treating it as POD, parses it as code, and fails with a syntax error. This includes `<<~` heredocs, where Perl strips the common leading whitespace: the relative indentation of the body lines is the meaning, so moving a single line changes the result.
- Why did my code come out unchanged?
- That usually means it was already correct, which is the best outcome. The worst failure for a formatter is not ugly output but altering correct code — that change lands in a diff and in code review, and it is hard to say who made it. So the strategy here is to act only when there is something to fix. When the code genuinely is misindented, the output does change.
- Will it change what my code does?
- No. Only the leading whitespace of each line is touched — not one character inside a line, no reordering, no re-wrapping, no line removal, nothing inside strings or comments, and heredoc bodies and POD are kept whole. So even with wildly unusual formatting the worst case is indentation you do not like, while the code still runs. By the same token, it cannot add missing syntax (a dropped bracket, a forgotten semicolon). It is an indentation tool, not a repair tool.
Related tools
JS Minify & Beautify
FormatMinify JavaScript (comments and whitespace stripped, /*! licences kept) or beautify it by re-indenting on braces and semicolons. Nothing is uploaded.
JS Obfuscate
FormatStrip comments and whitespace, escape strings and numbers, rename local variables — smaller, and harder to skim. All local.
Code Highlighter
WebColourise code and copy it with the colours intact into slides, Word or email — or export inline-styled HTML for a blog. 26 languages supported.
Shell Formatter
FormatIndent a shell script by structure: if/fi, for/done, case/esac and functions. Only leading whitespace changes; heredocs stay intact.
JSON Formatter
FormatFormat, validate and minify JSON in a collapsible tree with syntax highlighting and line numbers. Search, edit, delete or convert to Python dicts.
JSON to Code
FormatTurn JSON into TypeScript interfaces, Go structs, Java classes or Rust structs, with missing keys marked optional. Runs locally in your browser.