I have a text file , lets call it file1.txt :

```
cats
and
dogs
are
running
around
|

john
loves
mary
|

I
am
swimming 
|

```

I am trying to build a program which looks for the words ending with 'ing' and prints CC beside them on the same file or to a different output.txt file.

Desired Output

```
cats
and
dogs
are
running  CC
around
|

john
loves
mary
|

I
am
swimming CC
|

```

I went through the available articles in the forum and tried building the following code ,however it gives me an arbitrary result with every word followed by " CC ".

```
use warnings;
use strict;

my $file = 'file1.txt';

open(my $word_fh,"file1.txt") or die "Couldn't open file file1.txt, $!";

my %word_match = map {chomp $_; $_ => 0} <$word_fh>;

close $word_fh;

open my $fh, '<', $file or die $!;

while (<$fh>){
    chomp;

    my @words_in_line = split;

    for my $word (@words_in_line){

        $word =~ /ing$/;
        $word .= '  CC' if exists $word_match{$word};

         print "    $word\n";
    }
    }

```

The output that I get is this :

```
cats    CC
and CC
dogs    CC
are CC
running CC
around  CC
|   CC
john    CC
loves   CC
mary    CC
|   CC
I   CC
am  CC
swimming
|   CC

```

I know I am doing something wrong. Any hints or suggestions would be appreciated. Thanks in advance !