Thanks for the help
####
I have added small code which will check the condition first, if the line contain Link encap and if it found then get the ethernet address and ip address other wise skip the test.
and here is my changes.
open FILE,"config.txt" or die "cannot open file : $!";
my $interface; # declare the variable
while() {
if (/Link encap/){
print "yes";
# if there are non-space symbols on the start of the line,
# consider it interface name
$interface = $1 if /^([\S]+)/; # $1 means first matched () group of symbols
# a group of numeric symbols or dots after "inet addr:"
# is considered an IP-address
print "$interface => $1\n" if /inet addr:([0-9.]+)/;
# use /inet6? addr: ?([0-9a-f.]+)/ if you want to match IPv6-addresses
}
}
####
But when I run the script it gives me the below output but not giving the expected out.
"Yes"