#!/usr/bin/perl use strict; use warnings; use Set::CrossProduct; $, = "\n"; print map { chomp; s/\s*(#.*)?$//; map { join ".", @$_ } Set::CrossProduct->new( [ map { [ m/(\d+)-(\d+)/ ? $1 .. $2 : $_ ] } split /\./ ] )->combinations; } ; __END__ 172.17.119.2 # Comments are here... 172.17.119.4-5 # Comments are here... 172.19-21.254.2-3 # Comments are here... 192.168.1.1-3 # Comments are here...