my %hash; $hash{$_} = some_output($_) for @array; # Print each in arbitrary order like so: print $hash{$_} for keys %hash; # Print in original sequence by reusing the array: print $hash{$_} for @array; sub some_output { local $_; # Insert mystery code here }