如果文件不大的话,可以把文件读入数组,然后再处理保存到另外一个文件里。
#!/usr/bin/perl -w
use strict;
my @file = `cat /usr/home/cel/sample.txt`;
open FH,">>/usr/home/cel/newfile.txt" or die "Can't open /usr/home/cel/newfile.txt: $!\n";
foreach my $i (0..$#file){
chomp $file[$i];
next if $i == 0;
next if $i == $#file;
print FH "$file[$i]\n";
}
close FH;