my $j = 1; my $p = $s[1]; #values are present starting from 1st index while ($j != $n - 1) { if ( ($p < $s[$j+1]) || ($p == $s[$j+1]) ) { }else{ $p = $s[$j+1]; } $j++; } #### use strict; use warnings; use Data::Dump; my @s= map { int rand 100 } 1..10; dd \@s; my $min_idx = 0; my $idx = 0; my $min = $s[0]; for my $value (@s) { ($min,$min_idx)=($value,$idx) if $value < $min ; $idx++; } dd $min,$min_idx; #### [96, 40, 65, 98, 46, 17, 2, 60, 12, 67] (2, 6)