use strict; my $input_file = 'foobar.txt'; open my $in, $input_file or die "Failed to read $input_file: $!\n"; my @max = do { local $_ = <$in>; chomp; [ split ] }; my $last = $max[ 0 ][ 1 ]; while ( <$in> ) { chomp; my ( $x, $y ) = split; if ( $y > $last ) { $max[ -1 ] = [ $x, $y ]; } elsif ( $max[ -1 ] ) { $max[ @max ] = undef; } $last = $y; } close $in; pop @max unless $max[ -1 ]; print "Maxima:\n"; print "($_->[ 0 ], $_->[ 1 ])\n" for @max;