in reply to convert text to HTML Format Table.

if your text file already has (literal) <h1>, etc, why don't you just copy it to a new file and rename that foo.htm? (You'll probably have to add at least minimal html headers and close the heading tags, but that's a different script). For most in-house purposes that occur to me (insufficient imagination may be a work here), that would be fairly simple.

If your output is intended for the global population of the web, please reconsider nesting tables.

Most current browsers don't exact the kind of speed penalties we saw under NS 4 and IE5 (data lacking for Konqueror, Safari, etc), but there is still some... and another for failure to specify width ... preferably with css (tho, personally, because my logs tell me there are still quite a few users of NS4.7, IE 5.0, etc., I stick widths (as %) in <table... and <td elements to cope with those browsers' poor/flaky handling of css and inheritance.

If your H1, 2, 3 are intended to resemble classic 7th grade outlining", the suggestions above look sensible; if you're not dealing with a simple outline, you probably should consider someting like:

open (test that its open: use die!!!) and read original file into array
open a filehandle (OFH) for output (and test)
print OFH "<html><head><title>$1</title></head><body><table><tr>";
(where $1 is the orig filename)
foreach $line(@array) { print OFH "<td>$line</td></tr><tr><td>"; } print OFH "/td></tr></table></body></html>"; close, etc...

This will keep the <Hn tags from your original, though neither approach I've mentioned will keep the indentation.

add newlines to taste if you're going to need to read/tweak the html