for ( my $i=$#history; $i >=0; $i-- ) { # for $i = (last index of @history) to 0 $_ = $history[$i]; # get the value from the position in @history !$history{$_} # test if that value has been seen before ? $history{$_} = 1 # if it hasn't record it : splice @history, $i--, 1) # if it has remove it from @history # (reducing $i to compensate for its remove; }