$tempfile = "jojowashere.jbc"; if ($#ARGV < 0) { print "\nUSAGE: $0 filename.cat"; exit(0); } open (fp,$ARGV[0]) || die ("Can't open $ARGV[0]! Exiting."); open (tempfp,"> $tempfile") || die ("Can't create $tempfile! Exiting."); while() { if (m/(^.*)(".+")(.*)/) { $a = $1; $b = $2; $c = $3; $a =~ s/\(/\n\(\n/g; $a =~ s/\)/\n\)\n/g; $c =~ s/\(/\n\(\n/g; $c =~ s/\)/\n\)\n/g; $_ = $a . $b . $c; } else { s/\(/\n\(\n/g; s/\)/\n\)\n/g; } print tempfp "\n$_"; } close fp; close tempfp; $num_indents = 0; open (fp,$tempfile) || die ("Can't open $tempfile!"); while () { s/^\s+//; s/\s+$//; chomp; if (length) { if (m/^\)$/) { --$num_indents; } $spacing = ""; for ($j=0;$j<$num_indents;$j++) { $spacing .= " " }; print "\n$spacing$_"; if (m/^\($/) { ++$num_indents; } } } close fp; unlink $tempfile;