use Data::Dumper; open (OUT1, ">alldata.txt") or die; %mycorpus = getCorpus('C:\Users\li\test11'); my $href = \%mycorpus; # reference to the hash %mycorpus print OUT1 Dumper $href; # note the order will differ from that above print OUT1 "\n"; open (OUT2, ">editeddata.txt") or die; open( FILE, "alldata.txt" ) || die "couldn't open\n"; $/ = undef; while () { while (/(?<=##)(.*)(?=##)/g) { print OUT2 "$1\n"; }