use strict; my $max = 0; foreach () { s/(\r|\032)$//; $max = length($_) if length($_) > $max; } print " " x $max; __DATA__ This is my file it doesn't have a blank line at the end of it based on the maxline count of the file that it read.