use strict; use warnings; use feature qw( say ); use List::Util qw( max ); <>; while (<>) { chomp; my @fields = split /;/; my %indexes; push @{ $indexes{ $fields[$_] } }, $_ for 1..$#fields; say join ",", @{ $indexes{ max keys %indexes } }; } #### perl -MList::Util=max -F\; -lanE' BEGIN { <> } my %indexes; push @{ $indexes{ $F[$_] } }, $_ for 1..$#F; say join ",", @{ $indexes{ max keys %indexes } }; '