my %hash; for my $element (@array) { $hash{$element} = ; } ... for $element (@array) { # Keep the same order as the original array print "For $element, output was $hash{$element}\n"; }