use strict; use warnings; sub check_condition { my( $inst, $cond, $ors ) = @_; OR: for ( @$ors ) { $inst !~ /$_/ and next OR for @$_; return 1; } return 0; } sub check { my( $inst, $list ) = @_; return grep { check_condition $inst, $_, $list->{$_} } keys %$list; } my %conditions = map { /^(.*?)=(.*)$/; $1 => [ map { [ split /,/ ] } split /\|\|/, $2 ]; } ; my @instances = qw( IDL_MANAGEMENT_101001 IDL_NORTH_TX IDL_SOUTH VIDL_NORTH ABX_PERL ); print "$_:", join(",",check( $_, \%conditions )), "\n" for @instances; __DATA__ MANAGEMENT=IDL NORTH=IDL,NORTHERN||VIDL,NORTH||IDL,NORTH SOUTH=IDL,SOUTHERN||CIDL,SOUTH