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