our @array = 'a' .. 'e'; our @figure_out = 'd' .. 'g'; { my $index = 0; my %h = map {$_=>$index++} @array; while( my($k,$v) = each %h ){ my $n = shift @figure_out or next; $h{$n} = $index++ unless exists $h{$n}; } @array = sort {$h{$a}<=>$h{$b}} keys %h; }