use File::ReadBackwards; open(my $fh, "test") or die("ack - $!"); my $first = <$fh>; close $fh my $last = File::ReadBackwards->new("test")->readline;