--$hash{'AirIATA'}= get_IATA($airlineLoc,$hash{'Airline'}) ; ------------------------------------------------------- sub get_IATA { my $file = shift; my $airline = shift; my @data; open(my $fh, '<', $file) or die "Can't read file '$file' [$!]\n"; while (my $line = <$fh>) { my @fields = split(/;/, $line); push @data, @fields; } close($fh); my @results= map { $data[$_] =~ m{ \A \Q$airline\E }xms ? $data[$_ + 1] : () } 1 .. $#data; if ($#results>1) { return $results[1]; } elsif ($#results>0) # Do I need a second check, like <2 ? { return $results[0]; } else { print "Airline $airline has no definition in $file file\n"; exit; # Program should stop if there is no match } }