while () { if ( /^interface (\S+)/ ) { $cur_int = $1; $int{$cur_int}{ip}=""; } elsif ( /^ ip address ([\d\.]+) ([\d\.]+)$/ ) { my ( $ip, $mask ) = ( $1, $2 ); $int{$cur_int}{ip}=MyIP->new($ip, $mask) or die "incorrect IP address: $ip $mask\n"; print "$cur_int: $ip $mask = ", $int{$cur_int}{ip}->print_cidr(), "\n"; } }