#!/usr/bin/env perl use strict; use warnings; my $VAR1 = { ... as per your OP ... }; my (@all_states, @comment_states); for (map values %$_, values %$VAR1) { my ($state, $comment) = ('', 0); for (@$_) { $state = substr $_, 11 if 0 == index $_, 'state_name='; $comment = 1 if 0 == index $_, 'comments='; } push @all_states, $state if $state; push @comment_states, $state if $comment; } use Data::Dump; dd \@all_states; dd \@comment_states;