#!/usr/bin/perl use strict; use warnings; my @arr1 = qw(john:::10 bill:::9 mary:::35 willy:::21); my @arr2 = qw(9 35 10 21); my %hash = map { $_ =~ /:::(\d+)$/; ($1 => \$_); } @arr1; print for map { $$_ } @hash{@arr2};