#!/usr/bin/perl # http://perlmonks.org/?node_id=1185598 use strict; use warnings; my @array = qw(world today is very nice); my %hash = (0 => "Hello", 1=> "world" , 2=> "today" , 3=> "is" , 4=> "nice", 5=> "is"); my %reversehash; # allow for different keys mapping to the same value push @{ $reversehash{$hash{$_}} }, $_ for keys %hash; my @newarray = map @{ $reversehash{$_} // [] }, @array; use Data::Dumper; print Dumper \@newarray;