Problem with sed in perl!!

Hi,
I am facing an issue with sed in perl. I have a file which has 2 header lines and one trailer line. I need to process the file without these headers and trailer. My file looks like :
File.txt:-

Header1
Header2
data1
data2
trailer

For removing header and trailer from file I am using the following command in perl file:

system (`sed '1d;2d;$d' File.txt > NewFile.txt`);

The problem is, when I am excuting this perl script it is just removing the Headers only and not the trailer from the file.
But when I am directly running this command on command line:

sed '1d;2d;$d' File.txt > NewFile.txt

It is running fine and is removing both headers and trailer from the file. Not sure, why the same command is working differently in perl??
Any help would be highly appreciated.
Thanks..

The problem is that you are trying to use sed in a Perl program.
That's like clubbing someone to death with a loaded Uzi, as Larry Wall says.

Perl is a full-fledged scripting language and I'd think it could do everything that sed could do. Maybe better.

$
$
$ cat f9
Header1
Header2
data1
data2
trailer
$
$
$
$ perl -lne 'print "DATA => $_" if $. > 2 && !eof' f9
DATA => data1
DATA => data2
$
$

tyler_durden

Thanks for the reply!!
You are right!! but can anybody please let me know how to use this command in a perl file? If i am copying this command directly in perl file, it is not running and throwing out errors.
I need to redirect the output of this command to a file which will only contain data and no header and trailer information.

Thanks,

Tyler is completely right but if u want to go on that way check your syntax:

system('sed \'1d;2d;$d\' File.txt > NewFile.txt');

Yeah.. it worked now..

I tried below command:
system(`sed '1d;2d;\$d' File.txt > NewFile.txt`);

Thanks everybody

It is strange that, why do you have both 'backtick' and system... both are for execution of shell command, and you have to use one.

Whats the reason behind that ?

And as your backtick does the variable interpolation, you got the $d not working, and \$d to work..