open(EMPLOYEES,'test.txt') or die; while (my $line = ) { #remove the carriage return chomp $line; #splits the line between tabs and get the different elements my ($name, $city, $language) = split /\t/, $line; next unless $language =~ /$search/; print "$name can speak " . ($search) . " and lives in " . ($city) . ".\n"; } print "Sorry, your query produced no results.\n" if (eof(EMPLOYEES));