in reply to Code stalls...possible memory leak?

Assuming that your file is always balanced and there are no qouted { or }, it can be made much simpler. (I didnt bother looking into your regex's or the Text::Balanced more than breifly, so bare over with me if this is not what you want)
#!/usr/bin/perl -w use strict; #input print "Name of file to be inputted? :"; $infile=<>; print "What should the output file be named? The file will be automati +cally created. :"; $outfile=<>; chomp $infile; chomp $outfile; ##<<<<<<<<<You forgot this one open INFILE, "<$infile"; #output open FILEOUT, ">$outfile"; my @stack; while(<INFILE>) { my @op = (); my $len = length($_); my $minsta = 0; my $minsto = 0; my $lastpos = 0; while(true) { $minsta = index $_,'{',$minsta; $minsto = index $_,'}',$minsto; last if ($len == $lastpos || ($minsta == -1 && $minsto == -1)); if ($minsta < $minsto) { my $nextsp = index $_,' ',$minsta; $nextsp = length($_) if ($nextsp == -1); my $stack = substr $_,$minsta+1,$nextsp-$minsta; push @op, (substr $_,$lastpos,$minsta-$lastpos), '<',$stack,'>'; push @stack, $stack; $lastpos = $minsta+1; } else { my $stack = pop @stack; die "Not balanced" unless (defined $stack); push @op, (substr $_,$lastpos,$minsto-$lastpos), '</',$stack,'> +'; $lastpos = $minsto+1; } } print OUTFILE join "",@op,(substr $_,$lastpos,$len-$lastpos); } close INFILE; close FILEOUT; die "Not balanced" if (@stack); print "\nYour result is stored in file $outfile\nGoodbye.\n";
I may have some offby 1 errors, solve them if you find it usefull...

This will use almost no memory and prob do the same jobs a LOT faster.

Update:
Well, seems tilly had the same idea as I, and dinner interrupted me so he got it first ;)

T I M T O W T D I