Perl Script Tidier & Indenter
Paste messy Perl scripts to tidy with proper indentation, brace style, and consistent formatting
Paste messy Perl — crammed one-liners, mixed tabs, inherited sysadmin scripts with zero formatting — and get clean, properly indented code back in one click. Pick K&R or Allman braces, choose your indent width, and the formatter rebuilds the structure while leaving regex, heredocs, and string literals untouched. And everything runs in your browser. Nothing gets uploaded.
How It Works
The formatter tokenizes your Perl source, tracking block depth through curly braces, parentheses, and bracket pairs. It recognizes string literals, regex, heredocs, and comments so it won't mangle anything inside them. Then it rebuilds each line with the indent level and brace placement you chose. The result is syntax-highlighted and ready to copy or download as a .pl file.
Examples
Cleaning Up a One-Liner Script
Someone pasted a compact script into Slack and you need to actually read it.
use strict;my @nums=(1..10);foreach my $n(@nums){if($n%2==0){print "$n is even\n";}else{print "$n is odd\n";}}
use strict;
my @nums = (1..10);
foreach my $n (@nums) {
if ($n % 2 == 0) {
print "$n is even\n";
} else {
print "$n is odd\n";
}
}
Switching from K&R to Allman Braces
Your team's style guide requires opening braces on their own line. Doing it manually across 400 lines? No thanks.
sub process_file {
my ($path) = @_;
open(my $fh, '<', $path) or die "Cannot open: $!";
while (my $line = <$fh>) {
chomp $line;
print "$line\n";
}
close $fh;
}
sub process_file
{
my ($path) = @_;
open(my $fh, '<', $path)
or die "Cannot open: $!";
while (my $line = <$fh>)
{
chomp $line;
print "$line\n";
}
close $fh;
}
Formatting a Messy Hash and Regex Block
Legacy code with hashes crammed onto single lines and regex patterns buried in conditionals.
my %config=('host'=>'localhost','port'=>3306,'db'=>'prod');if($input=~/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}$/i){send_email($config{'host'},$input);}else{warn "Bad email: $input\n";}
my %config = (
'host' => 'localhost',
'port' => 3306,
'db' => 'prod'
);
if ($input =~ /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z]{2,}$/i) {
send_email($config{'host'}, $input);
} else {
warn "Bad email: $input\n";
}
Who Uses This
Cleaning up automation scripts inherited from whoever had the job five years ago.
Reformatting BioPerl pipeline scripts before a code review or publication.
Tidying legacy CGI or Catalyst code that's still running in production.
Formatting homework submissions so the professor can actually follow the logic.
Common Mistakes
If your Perl has an unclosed brace or missing semicolon, the formatter will still try its best — but the output indentation might look wrong. Fix syntax errors first, then format.
This is a formatter, not a linter. It fixes indentation and brace placement. It won't rename $x to $count or suggest better patterns. That's what Perl::Critic is for.
If your source has mixed tabs and spaces, the formatter normalizes everything to your chosen indent style. That's the right behavior — but double-check heredoc blocks afterward, since whitespace inside heredocs is meaningful in Perl.
Technical Details
- Processing: 100% client-side — code never leaves your browser
- Browser Support: Chrome, Firefox, Safari, Edge
- Indent Options: 2 spaces, 4 spaces, or tabs
- Brace Styles: K&R (same line) or Allman (new line)
- Output Formats: Copy to clipboard or download as .pl file
Frequently Asked Questions
Is there a free online Perl code formatter?
Yes, this one. Paste your code, pick your settings, click Beautify. No account needed, no install, no cost. It runs entirely in your browser so there's nothing to set up.
What is the difference between K&R and Allman brace style?
K&R puts the opening brace on the same line as the statement: if (...) {. Allman drops it to its own line. Most Perl code uses K&R because that's what Larry Wall did. Pick whichever your team agrees on — consistency matters more than the choice itself.
Does this tool handle Perl regex and heredocs correctly?
It recognizes regex literals and heredoc blocks so it won't try to reformat the content inside them. The indentation around those constructs gets fixed, but the actual pattern or heredoc text stays untouched.
How is this different from perltidy?
Perltidy is a Perl module you install and run from the command line with dozens of config options. This tool handles the most common formatting tasks — indentation and brace style — right in your browser. If you need fine-grained control over continuation indentation or vertical alignment, perltidy is the way to go. For a quick cleanup, this is faster.
Is my code safe? Does it get sent to a server?
No server involved. The formatting happens in JavaScript inside your browser tab. Nothing is uploaded, logged, or stored. You can disconnect from the internet and the tool still works — try it.