in reply to Manipulating a file

Your code requires a "}" to be inserted at line 37, to compile, has several warnings, and the line 19:
$data = $1;
makes no sense.

Please make an attempt at actually addressing the problem, post code that compiles, and ask specific questions about the parts that do not do what you expect.

        What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
              -Larry Wall, 1992