@hash{@alphafiles}=(); foreach (keys %hash){ my $patt=substr($_,0,index($_,"xml")); @matched=grep(/^$patt/,@gammafiles); $hash{$_} = $matched[0]; }