open(my $f, $your_file) or die("ack: $!"); seek($f, int rand(-s $f), 0); { local $/ = \1; ## anyone care to optimise this? seek($f, -2, 1) until ($c = <$f>) eq "\n" or tell($f) == 0; } print scalar <$f>;