Q:

Error when extracting words offset in perl

I have a program that read tow files, the first file contain terms (one, or multiterms) seprated by  semicolon (; ), the second file contain text, the goal is to determine the offset of the terms in the first file! 
My program begin well fluctuating vacuum (correct offsset extracted 2 20, also 45 59 for quantum fields)    , but when extracting the offset for example for terms  nuclear physics (correct ofsset 396 411) my code generate 399 414!    or Fermionic fields (my code generate  138 154) but the correct is 135 151 
The code used is:
#! /usr/bin/perl
use strict;use warnings;

my @a = ();
my @b = ();
my @aa = ();
my $l=0;
my $v=1;
my $g=0;
my $kh;
my $ligne2;
my $texte;

open(FICC, $ARGV[0]);

print "choose the name of the file\n";
my $fic = <STDIN>;

open(FIC1, ">$fic");

while (<FICC>) {
    my $ligne2=$_;
    $a[$l]=$ligne2;
    $l++;
}

my $aa;
my $ligne;
my $rep = "C:\\scienceie2017_train\\train2";
opendir(REP,$rep) or die "E/S : $! \n";

foreach my $kh (@a) {
    chomp($kh);

    if ($kh=~/.*\.txt/) {
        $texte=$kh;
        #print "$kh";
        print FIC1 "$texte";
    }

    @aa=split(/;/,$kh);
    #$u++;
    while(defined(my $fic=readdir REP)){
        my $f="${rep}\\$texte";
        open FIC, "$f" or warn "$f E/S: $! \n";
        while(<FIC>){
            $ligne = $_;
            chomp($ligne);
            #print FIC1 "@aa";

            foreach my $che (@aa) {
                $che =~ s/^\s+//; 
                $che =~ s/\s+$//;
                if ($ligne =~/\Q$che\E/) {
                    print FIC1 "T$v\tTask $-[0] $+[0]\t$che\n";
                    $v++;
                }
            }
            $v = 1; 
        }
        print FIC1 "\n";
        close FIC;
        goto che
    }
che:
}

The text is:

A fluctuating vacuum is a general feature of quantum fields, of which the free Maxwell field considered in  [1–12] is but one example.  Fermionic fields such as that describing the electron, also undergo vacuum fluctuations, consequently one expects to find Casimir effects associated with such fields whenever they are confined in some way.  Such effects were first investigated in the context of nuclear physics, within the so-called “MIT bag model” of the nucleon  [13].  In the bag-model one envisages the nucleon as a collection of fermionic fields describing confined quarks.  These quarks are subject to a boundary condition at the surface of the ‘bag’ that represents the nucleon’s surface.  Just as in the electromagnetic case, the bag boundary condition modifies the vacuum fluctuations of the field, which results in the appearance of a Casimir force  [14–18].  This force, although very weak at a macroscopic scale, can be significant on the small length scales encountered in nuclear physics.  It therefore has important consequences for the physics of the bag-model nucleon  [19]. 

The extracted terms are:

fluctuating vacuum;general feature;quantum fields;free Maxwell;free Maxwell field;Maxwell;Maxwell field;Maxwell field;Maxwell field;field considered in ;considered in ;1–12;Fermionic fields;vacuum fluctuations;Casimir;Casimir effects;Casimir effects;Casimir effects;such fields;Such effects;nuclear physics;so-called “MIT;so-called “MIT bag;“MIT bag;“MIT bag model”;bag model”;fermionic fields;fermionic fields describing;boundary condition;nucleon’s surface;electromagnetic case;bag boundary;bag boundary condition;boundary condition;vacuum fluctuations;Casimir;Casimir force ;force ;14–18;macroscopic scale;small length;small length scales;length scales;nuclear physics;important consequences;bag-model nucleon ;

A:

You must open your filesin UTF8
reaplce
open FIC, "$f" or warn "$f E/S: $! \n";

by
open FIC, "<:encoding(UTF-8)", "$f" or warn "$f E/S: $! \n";

