# take IP4 address string my $IP_str = '192.0.2.4'; # convert the numbers to hex my @IP4_a = map { sprintf("%02x", $_) } split(/\./,$IP_str); # embed these hex numbers in the IPv6 template my $R = sprintf("2002:%s%s:%s%s::/48", @IP4_a); # output the result die "($R)"; #### sub ipv4_6to4{ return sprintf("2002:%s%s:%s%s::/48", map {sprintf("%02x",$_)} split(/\./,$_[0])); }