foreach $name (keys %book) { #write the data print "$name \n"; $name =~ /(.+)&(.+)/; print "$1, $2 \n"; if ($2 =~ /^0$/) { print BOOK "$1,::"; } else { print BOOK"$1,$2::"; } for ( 0 .. $#{ $book{$name} } ) { print BOOK $def[$_+2] . ":" . $book{$name}[$_] . "::" unless $book{$name}[$_] =~ /^0$/; } print BOOK "\n"; }