Try this regex for detecting an IPv4-compatible IPv6 address: ... =~ qr/^::FFFF:(\d{1,3}(\.\d{1,3}){3})$/i ... That should be more precise than strchr(...,'.'); $1 should be the IPv4 address that was extracted.