IMO the
eval version is
much clearer than anything involving
pack/
unpack could be.
$ perldoc -f eval|wc -c
6610
$ perldoc -f pack|wc -c
23377
That's right,
pack's documentation is over three and a half times longer, and is littered with platform dependencies, arbitrary one character magic values, and special cases. It's so complicated that it needs a 51,000 character tutorial to go with it.
And your use of << is buggy. On a 32 bit machine the results are undefined. On a 64-bit machine you lose the obvious relationship between the /bits and the netmask (you'll have too many 1 bits) although the results will still be correct as the extra 1s will be ANDed with 0 and so thrown away later.