my %profile = ('MARTIN' => 28, 'SHARON' => 35, 'RIKKIE' => 29,); foreach $item @ARGV { @otherpatProf = map{ uc } /[[:alpha:]]/g; $other_pat = join '(.*)', sort @otherpatProf; print "***$_\n"; foreach (grep{ /.*$other_pat.*/ } keys %profile) { $smprofile = join "", /(.*)$other_pat(.*)/g; next unless $profile{$smprofile}; print "$profile{$_} $profile{$smprofile}\n"; } }