my $x = '255.0.0.0'; print "$x is a valid mask!\n" if validateMask($x); sub validateMask { return # return undef if it's not complete unless $_[0] =~/^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/; $_[0] = unpack ( "B32", pack( "C4", split ( /\./, $_[0] ) ) ); return # return undef if we find an invalid if $_[0] =~ /01/; # mask ( a zero followed by a one ) return 1; # return 1 if everything is okay }