$infile = shift || die "Need a filename!\n"; open(INFILE, "$infile") || die "Could not open $infile: $!\n"; while() { chop; tr/A-Z/a-z/; ## lowercase all characters s/\s+/ /g; ## remove extra spaces for $x (split(/\d*\./, $_)) { ## Set each to "0" if not found in the hash: $site = $site{$x} || "0"; $specimin = $specimin{$x} || "0"; $procedure = $procedure{$x} || "0"; ## Do not go on if any were not found: next unless ($site && $specimin && $procedure); ## Grab the results of assigncode: $code=&assigncode($site,$specimen,$procedure); ## Exit while loop if a good $code is found: last if $code; } } close(IN); print "$code " if $code; print "$line\n";