#!/usr/bin/perl print "Search for what: "; chomp(my $search = ); @words = split(/ /, $search); # Turn words into regular expressions @words = map {qr/$_/i} @words; # If you don't want the user to have to # worry about regex syntax, use this instead: # @words = map {qr/\Q$_/i} @words open(DATA, "books.txt") or die "error opening file $!"; while () { $matches=0; foreach $word(@words) { if ($_ =~ $word) { print unless ($matches > 0); $matches++; } } }