#!/usr/bin/env perl use Modern::Perl; my ($c, $d, $i) = ([qw(7 5 3 0 9 18 12)], [qw(a b c d e f g)], 0); say $d->[[(sort {$a->[0]<=>$b->[0]} map {[$_,$i++]} @{$c})]->[0][1]];