If the file is too big to fit in memory at one time, you can try this solution.
==================
$firstline = "";
$lastline = "";
open IPF, "filename" or die "Error opening input file: $!";
$firstline = <IPF>;
while(<IPF>) {$lastline = $_;}
==================
This grabs the first line into $firstline. The location of the next read from the file will be line 2. The while() loop reads the file line by line and assigns the current line to $lastline. When there are no more lines, $lastline contains whatever the last line in the file was.
I explicitly created $lastline ouside the while() loop so there wouldn't be scope issues. Doing that for $firstline wasn't really necessary, but it appealed to my sense of symmetry

.
This is probably slower than reading the whole file into memory, but it should work for arbitrarily large files. If you have confidence that your file size is small enough to fit in RAM, use icrf's solution for speed.
Share and enjoy.
obscurifer