[Need help] perl script to find the occurance of string from a text file

I have two files

  1. input.txt
  2. keyword.txt

input.txt has contents like

.src_ref 0 "call.s" 24 first
      0x000000    0x5a80 0x0060         BRA.l 0x60
.src_ref 0 "call.s" 30 first
      0x000002    0x1bc5                RETI
.src_ref 0 "call.s" 31 first
      0x000003    0x6840                MOV R0L,R0L
.src_ref 0 "call.s" 35 first
      0x000004    0x1bc5                RETI

keyword.txt has contents

MOV
BRA.l
RETI
ADD
SUB
..
etc

Now I want to read this keyword.txt file and search it in input.txt file and find how many times MOV has occured,how many times BRA.l has occured and so on.

So far I have managed to get it working from a single file itself. here is the code

#!/usr/bin/perl
use strict;
use warnings;

sub retriver();

my @lines;
my $lines_ref;
my $count;
$lines_ref=retriver();
@lines=@$lines_ref;
$count=@lines;
print "Count :$count\nLines\n";
print join "\n",@lines;

sub retriver()
{
    my $file='C:\Users\vk41286\Desktop\input.txt';
    open FILE, $file or die "FILE $file NOT FOUND - $!\n";
    my @contents=<FILE>;

    my @filtered=grep(/MOV R0L,R0L/,@contents);
    return \@filtered;
}

here i can search only MOV and i am unable to search other instructions like RETI.

I am a newbie on perl and this is not a assignment problem.

OUTPUT should be

MOV has occured 2  times
RETI has occured 1 time

Thanks for help/guide.

P.S : This question was posted on stackoverflow and all I could get is bash script , single command line. 

But what I need to perl script.

This is a crude form.. written quickly in 5 mins. It's not efficient and is a dirty job. If you see.. there are nested loops and if you have large input and keyword files, it might bring down the efficiency.

#! /usr/bin/perl -w
use strict;

my ( %keywords );
my ( $line, $key, $value );

open K, "< keyword.txt";
while ( $line = <K> ) {
    chomp ( $line );
    $keywords { $line } = 0;
}
close K;

open I, "< input.txt";
while ( $line = <I> ) {
    chomp ( $line );
    foreach $key ( keys %keywords ) {
        while ( $line =~ /$key/g ) {
            $keywords{ $key }++;
        }
    }
}
close I;

while ( ( $key, $value ) = each %keywords ) {
    print "$key has occured $value times.\n";
}

This script takes as its first argument the keyword list, and the second and subsequent arguments as the files to parse.

use strict;
use warnings;
use File::Basename;

$, = '';
$\ = "\n";

my $NAME   = basename $0;
my %COUNTS = ();

#-------------------------------------------------------------------------------
# Read in keyword list

my $keywordlistfile = shift @ARGV;
die $0, ': missing keywordlist' unless defined $keywordlistfile;

open KH, '<', $keywordlistfile or die $keywordlistfile;

while (<KH>) {
    chomp;
    $COUNTS{$_} = 0;
}

close KH;

#-------------------------------------------------------------------------------

while (<>) {
    my ($op) = m{^\s+(?:0x[0-9a-f]+ +)+(\S+)}i;
    next unless defined $op;
    $COUNTS{$op}++ if defined $COUNTS{$op};
}

#-------------------------------------------------------------------------------

while (my ($op, $n) = each %COUNTS) {
    printf "\%10d \%s\n", $n, $op;
}

USAGE:

parser keywordfile inputfile...

Given your example, the results would be:

        0 SUB
         0 ADD
         1 BRA.l
         1 MOV
         2 RETI