package Test; use strict; use Filter::Simple; FILTER_ONLY code => sub { no warnings; my @lines = split /\n/, $_; my @indents; for (@lines) { my ($indent) = /^(\s*)/; $indent =~ s/\t/12345678/g; $indent = length $indent; if ($indent > $indents[-1]) { s/^/{/; push @indents, $indent; } elsif ($indent < $indents[-1]) { while ($indent < $indents[-1]) { defined pop @indents or last; s/^/}/; } } } $_ = join "\n", @lines; $_ .= "}" x @indents; }; 1;