$_ = '192.168.2.111'; my @l; /^(?:([01]?\d\d?|2[0-4]\d|25[0-5])(?{push@l,$1})\.){3}([01]?\d\d?|2[0-4]\d|25[0-5])$/; print join('-',@l,$2),"\n"; __END__ 192-168-2-111