OK. It is homework, but some general comments on coding:
You have code duplicated in both the 'if' and the 'else' part - this could and should be moved to the end of the loop.
You have two variables (i and j), one of which is always one more than the value of the other. Your code would be cleaner if you only used 'i' and replaced 'j' with '(i+1)'.
You are using a windows system, which pretends to prefer to use '\' to separate folders. The '\' character is special in many places, including inside strings marked with double quotes ". You can either use a single quotes ' to mark your string (which means you don't have to double your \\ to make them work) or (much better) you can take advantage of the fact that windows is happy to use '/' as a file seperator. i.e.
should work fine, and has the advantage of working on Unix or Windows boxes.
Perl has lots of features to make code like this simpler. For example, reading an entire file into one variable doesn't require a loop (check the documentation for the '$/' variable in 'perlvar', you can loop through arrays without using 'i' or 'j' as index variables (check documentation for 'foreach' and 'shift,unshift,push and pop')
Most importantly, perl is really a nice language built around an excellent regular expression engine. For the kinds of text processing you want to do, check the 'perlre' documentation. Its the "right way" to do this kind of job.
Good luck with the coding.
PS. Where I refer to 'perlvar', 'perlre' etc, these are some of the standard documentation which comes with perl. On Windows with Activestate perl, you can often find this in HTML format on the Start button/Programs/Activeperl, and on all systems you can type "perldoc perlvar" (or whatever) at a command prompt and get the information.