use Algorithm::Loops 'NestedLoops'; my @hosts = NestedLoops([([1..254])x2], sub { "192.168.$_[0].$_[1]" });