#!/usr/bin/perl use warnings; use strict; my $infile = $ARGV[0]; print "List of entities in ", $infile, "\n"; #define regexes as search target (in the array @regexes) my $regex = qr/(&[^;]+;)/; open my $in, '<', $infile or die "Cannot open $infile for reading: $!"; #read input file in variable $xml my $xml; { local $/ = undef; $xml = <$in>; } #define output file open my $out, '>', 'ent-list.txt' or die $!; #output list of entities print {$out} "$1\n" while $xml =~ /$regex/g; close $in; close $out;