Help with arithmetic operation

I am using egrep to extract numbers from a file and storing them as variables in a script. But I am not able to do any arithmetic operations on the variables using "expr" because it stores them as char and not integers. Here is my code and the error I get. Any help will be appreciated.

#!/bin/sh
$x=`egrep "string" filename | grep -oE "[[:digit:]]{1,}"`
$y=`egrep "string" filename | grep -oE "[[:digit:]]{1,}"`
c=`expr $x + $y`

Error: expr: non-numeric argument

can you provide sample input!!!!!!!!!!!!!!!!!!

i used perl to solve the problem i had. thanks.

#!/usr/bin/perl
$n = `egrep -n "string" filename | egrep -o "[[:digit:]]{1,}" | sed q`;
$m = `egrep -n "string" filename | egrep -o "[[:digit:]]{1,}" | sed q`;
$c= $m - $n;
print $c

Hi,
Please kindly give more detail of your question.
For example, give us the input and the expected output.
:stuck_out_tongue: