print &popline("passcodes.txt",10,7); sub popline { my ($file, $lineswanted, $linelength) = @_; open DATA, "+< $file"; my @fileinfo = stat DATA; my %records = (); $records{filesize} = $fileinfo[7]; $records{wanted_bytes} = $lineswanted * $linelength; $records{readpoint} = $records{filesize} - $records{wanted_bytes}; # seek (DATA, -$records{wanted_bytes},2); # reads from the end of file, readpoint computation not necessary seek (DATA, $records{readpoint},0); # reads from beginning, used b/c readpoint computation needed for truncate my @lines = ; truncate(DATA,$records{readpoint}); return @lines; }