an array @morgr is created here and shuffled to look for the word in random lines of the file open (MORG, "< /home/sid/kwicionary/$filename") or die "Can't open $filename for reading: $!"; $path = "/home/sid/kwicionary/"; $indexname = "$path$filename.index"; sysopen(MIDX,$indexname, O_CREAT|O_RDONLY) or die "Can't open $indexname for read/write:$!"; build_index(*MORG, *MIDX) if -z $indexname; MORG:foreach (@morgr){ $line_number = $_; $line = line_with_index(*MORG,*MIDX,$line_number); if ($key =~ /\*/){ $key = substr($key,0,(length($key) -1)); @word = split(' ',$line); foreach (@word){ if ($_ =~ /$key/){ push (@morg_results , $_); } } }