use JSON; open(IN,"<:utf8","$ARGV[0]"); while() { if (m!^\s+({[^\{\|].+})!) { my $jt = $+; $jt=~s/\"/\"/g; my $json = new JSON; my $jp = $json->allow_nonref->utf8->relaxed->decode($jt); my $c = $jp->{'claims'}; # "claims":{"P31":[{"mainsnak":{"snaktype":"value","property":"P31","hash":"...","datavalue":{"value":{"entity-type":"item","numeric-id":5},...}... }...}], if (ref($c) eq 'HASH') { foreach my $ch (keys %$c) { if (ref($c->{$ch}) eq 'ARRAY') { foreach my $cg (@{$c->{$ch}}) { if (defined $cg->{'mainsnak'}->{'datavalue'}->{'value'}->{'notexist'}) {} ## THIS LINE } } } } } }