use strict; use warnings; use Tie::File; my $file = shift or die "usage: $0 file\n"; tie my @lines, 'Tie::File', $file or die "error: $!"; print $lines[$#lines]; # this is the last line in the file #### use Fcntl 'O_RDONLY'; # add this line # ... as before, then change the tie line as shown below tie my @lines, 'Tie::File', $file, mode => O_RDONLY or die "error: $!"; # ... as before