use Data::Dumper; .... # find all the entities in the current file if (/entity\s+(\w+)\s+is/i) { $hash{$1}{'name'} = $1; $hash{$1}{'fname'} = $vhd_file; push @entities, $1; } .... close VHD; } print Dumper(%hash);