in reply to Need to calculate IP address

If you want to do arithmetic on IPv4 addresses, it's easier to convert them into numbers first.

my $ip_num = unpack 'N', pack 'C4', split /\./, $ip_dotted; $ip_num = ( ( $ip_num - 1 ) ^ 1 ) + 1; $ip_dotted = join '.', unpack 'C4', pack 'N', $ip_num;

Note that inet_aton $ip_dotted (from Socket) can be used instead of pack 'C4', split /\./, $ip_dotted.
Note that inet_ntoa $ip_packed (from Socket) can be used instead of join '.', unpack 'C4', $ip_packed.