Well, maybe I can save you some work. If you want to do this, I suggest you to use Algorithm::Diff in its place
The example script "diff.pl" provided with the module Algorithm::Diff does exactly what you want and is ready to use. You will find it in the directory after unzip and untar this package (you will need to install the module before to be able to use it, of course):
diff.pl file1 file2
___
5+ this is the line 5 (in file 1)
5- this is the lime 5 (in file 2)
|