use strict; use warnings; use Data::Dump; use List::Util qw/first/; $\="\n"; # --- init my @fields = qw( RUN DISTRICT COPY TOTAL ); my %a = map { $_ => 1- int rand 3 } @fields; my %b = map { $_ => 1- int rand 3 } @fields; dd \@fields,\%a,\%b; # --- w/o List::Util my $last; my $field; for (@fields) { $field =$_; $last = $a{$_} <=> $b{$_} and last; } print "$field,$last"; # --- with List::Util print first { $last = $a{$_} <=> $b{$_} } @fields; print $last;