perl parse line

Dear all
anyone willling to help me..i have try so many time but still failed to get the ip address for line
when i print the line is like below

Connected to 192.168.1.13

#!/usr/local/bin/perl
foreach $line(@lines){
if ($line =~ /connected to/) {
$line=~/connected to(.*?) /;
$ip=$1;
}
}

thanks for any help are most appriacated

First, please use

tags:#!/usr/local/bin/perl
foreach $line (@lines) {
if ( $line =~ /connected to/ ) {
$line =~ /connected to(.*?) /;
$ip = $1;
}
}[/code]

Second, on your matches you're missing the 'i' flag (for case-Insensitive matching). Otherwise "connected" will never match "Connected"

You only need to check the line once:

Connected to 192.168.1.13

#!/usr/local/bin/perl
foreach $line(@lines){
   if ($line =~ /connected to (.*?)/i) {
      $ip=$1;
   }
}

but if there are many IP addresses you will want to push() the matches into an array that you can access after the "foreach" loop ends, or process them one by one as you loop through @lines, otherwise $ip will be the last match found in the array.