use XML::Twig; my $file = $ARGV[0]; $file =~ /(.+)\.xml/; my $outfile = $1.".snp" ; open my $out,'>',$outfile or die "Could not open file '$outfile' $!"; my $twig = XML::Twig->new ( twig_handlers => { 'Rs/MergeHistory' => \&MergeHistory, } ); $twig -> parsefile( "$file"); sub MergeHistory { my ($twig, $elt) = @_; print $out "\t"; print $out "rs"; print $out $elt->att('rsId'), ","; print $out "b"; print $out $elt->att('buildId'), ","; }