#!/usr/bin/perl use strict; use warnings; use XML::Parser; my %handlers = ( Char => \&print_text ); my $parser = new XML::Parser( Handlers => \%handlers ); # if a file name was given on the command line # open it as STDIN: if ( @ARGV == 1) { open( STDIN, $ARGV[0] ) or die "$ARGV[0]: $!"; } $parser->parse( \*STDIN ); sub print_text { # this is a callback invoked by XML::Parser with 2 params: # 1st is the parser object, 2nd is text print $_[1]; }