Trap grep output

We have a script that greps a file for an IP address. Once the address is found I'd like to trap the result and use it later in the script. For example I have a file called ips.txt, and it contains:

USA
http://123.123.123.123
CAN
http://210.210.210.210

When I grep for CAN, it returns CAN http://210.210.210.210. To get just the address, my grep statement is: grep CAN -A 1 ips.txt | grep http

If I could temporarily save the output of the grep command, I can use the http://210.210.210.210 address later in the script to connect to a site. Any ideas?

can't you store it in some variable??

That's what I'd like to do, but I can't get my head around it, I've tried...

var='grep CAN -A 1 ips.txt | grep http
echo $var

Which of course returns: grep CAN -A 1 ips.txt | grep http

But this is not what I want, I want the results.

use back quotes `command`

Figured it out, I was using the single quote instead of the backtick

are you new to unix world??

Pretty obvious I guess. I am actually a storage engineer, but I need to automate some cli scripts that will add storage to a Hitachi array.

BTW: It turns out I have to get this to work in Perl. I do the following and it retruns what I want, but it looks like it must have a lot of whitesapce after it, so I tried to strip it off with...

CODE:
#!/usr/bin/perl
print `clear` , "\n";
print "Site: ";
chomp ($site= <>);
$ asite=`grep $site -A 1 ips.txt | grep http`;
$ nw=`echo $asite | sed 's/^[ ]*//'`;
print "$nw\n";

EXEC CODE AND RESULTS
testsys> ./test.pl

Site: USA
sh: -c: line 1: syntax error near unexpected token `|'
sh: -c: line 1: ` | sed 's/^[ ]*//''
http://123.123.123.123

testsys>

I know there is a lot of space after the results, as I tested this by adding a couple of other vars and it moved them to the next line. Any ideas?