# Suck in the whole file my $text = do { local $/; <$fh> }; # use a nested group to exclude the close tag while ($text=~ m{]*>(?:(?!).)*}s) { # print out the content of each ReportHost tag print "$1\n"; }