#!/usr/bin/perl use strict; use Fcntl qw(SEEK_END SEEK_CUR); my $f = shift; open F, "+<", $f or die "Couldn't open $f: $!\n"; seek F, -1, SEEK_END; seek F, -2, SEEK_CUR while (getc(F) eq "\n"); truncate F, tell F;