$data = $xml->XMLin($input_file); foreach $g (@{$data->{reaction}}) { foreach $h ($g->{substrate}){ $temp1 = $h->{name}; foreach $i ($g->{product}->{name}){ $temp2 = $i->{name} print "$temp1 -- $temp2\n"; } ] }