my $VAR1 ; while (my ($file,$val) = each %hash) { $VAR1 .= ">dataset\n". $file."\n". ">instances\n". join("\n",@{$val})."\n"; } print $VAR1;