my %hsh; push @{$hsh{$data[$_]}}, $_ for 0..$#data; for (keys %hsh) { printf '$data[%d] and $data[%d] have the same value!!', @{$hsh{$_}} if @{$hsh{$_}} == 2; }