#!/usr/bin/perl use warnings; use strict; use List::Util qw/max/; <>; # skip header for my $line (<>){ my ($chr, $nr, $begin, $end, @values) = split ' ', $line; my %total; while (@values) { my $class = shift @values; my $total = shift @values; $total{$class} = $total; } my $max = max values %total; my @maxes = grep $total{$_} == $max, keys %total; if (@maxes == 1) { print "$chr $begin $end $maxes[0]\n"; } else { print "$chr $begin $end undefined\n"; } }