sub gen2nfs_sub_ifconfig_ipv4 { my $ethif = shift; my $ifconfig = "$IFCONFIG"; my $string = 'inet\saddr:'; local *IFCONFIG; open (IFCONFIG, "$ifconfig $ethif 2>&1 |") || die ("ERROR (gen2nfs_sub_ifconfig_ipv4): $! $_"); while() { # search IP 123.123.123.123 # ddd.ddd.ddd.ddd # \d = digit # {1,3} 1,2 or 3 digits if ( /^.*$string(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/ ) { return "$1"; last; } else { die ("ERROR (gen2nfs_sub_ifconfig_ipv4): $! $_"); }; } close (IFCONFIG); }