in reply to truncate only a last blank line

can be this:
#!/usr/bin/perl while(<./*.txt>){ print "working on $_\n"; open (FH, "+<$_") or die "can't update $file: $!"; $l=$_ while <FH>; truncate FH, tell(FH) - 1 if $l =~ /^$/; }