use strict; use XML::Parser; my $parser = new XML::Parser( Handlers => { Start => sub { my ($expat,$tag,%attr) = @_; print $attr{'molecule_idref'}, "\n" if %attr and exists $attr{'molecule_idref'}; } } ); $parser->parse(\*DATA); __DATA__ fgdfg fgd fgdfg fg some text about how to write things containing molecule_idref="666".