#!/usr/bin/perl use strict; use warnings; use Set::CrossProduct; while( ) { chomp; s/\s*#.*//; my @b = map { [ m/(\d+)-(\d+)/ ? $1 .. $2 : $_ ] } split /\./; my $cross = Set::CrossProduct->new( \@b ); while( my $array_ref = $cross->get ) { print join( ".", @$array_ref ), "\n"; } } __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...