sub with_file_do { my( $filename, $each_line_cb ) = @_; my $fh = new IO::File "< $filename" or die "read $filename - $!"; chomp, $each_line_cb->($_) while <$fh>; } my $max; with_file_do( $scores_file, sub { my( $score ) = @_; !defined $max || $max < $score and $max = $score; } ); print "max=$max\n";