lll.pl: sub longestLineLength { my $longestLen = undef; for my $l ( @_ ) { if ( length($l) > $longestLen ) { $longestLen = length($l); } } return $longestLen; } test-01.pl: #!/usr/bin/perl require "lll.pl"; open (TOP, "/usr/bin/top -bcS -n 1 |") || die "open pipe from top failed $!"; print longestLineLength( ) . "\n"; $ ./test-01.pl 80