my $stuff = 'file.txt'; open(F, "$stuff") || die "Can not open file: $!\n"; my @records = (); print "@records\n"; s/lastlineofdata//; #This is the part I am struggling with close(F); #### use strict; use warnings; use IO::File; my $filename = 'file.txt'; my $in_fh = IO::File->new($filename) || die "Can not open '$filename' for reading: $!\n"; my @records = <$in_fh>; $in_fh->close; print "@records\n"; pop @records; my $out_fh = IO::File->new(">$filename") || die "Cannot open '$filename' for writing: $!\n"; print $out_fh, @records; $out_fh->close; #### perl -pi -e 'last if eof()' file.txt