use strict; use warnings; use feature 'say'; # This section creates a temporary file for testing my $file = "/tmp/$0.txt"; open TMP, '>', $file or die "Died: $!"; print TMP for (); close TMP; #-------------------------------------------------# print 'Which line would you like to measure? '; chomp( my $wanted = ); die 'Died: wanted line number required' if not $wanted; open my $FH, '<', $file or die "Died: $!"; while ( my $line = <$FH> ) { chomp $line; if ( $. == $wanted ) { say "The length of line $wanted ('$line') is " . length $line; last; } say "Reached end of file before line $wanted" if eof; } # remove the test file unlink $file; __DATA__ heaven heavenly heavenns abc heavenns heavennly