use warnings; use strict; my $max = 0; while (<>) { my $len = length; $max = $len if $len > $max; } print "$max\n"; #### a abc abcdef abcd abcde #### 1 2 3 12345678901234567890123456789012345678 #### perl -nE'$l=y///c;$m=$l if$l>$m;END{say$m}' file.txt