# I remove the C-style comments prior to this my @lines = split(/\n/,$list); my $level = 0; for (@lines) { print "$level:$_\n"; $level++ if /\{/; $level-- if /\}/; }