my @folge; for (@$best) { my $i = 0; for my $k (@prio) { (my $copy = $k ) =~ tr/0-9//cd; push @folge, $prio[$i] if $_ == $copy; $i++ } }