use strict; use HTML::TreeBuilder 3; open(WRITE_FH, '>', $filename) or die "cannot open $filename"; select WRITE_FH; # ... # ... everything you print should be redirected to your file # ... my $root = HTML::TreeBuilder->new; $root->parse_file('file2.html'); my @div_class = $root->find_by_attribute("class","forminput"); foreach my $node (@div_class) { print $node->content_list(); print "\n"; } close WRITE_FH; #prnt elements in array: open( my $fh, '<', $filename ) or die "Can't open $filename: $!"; my @line = <$fh>; print "\n"; print "Computer Name: $line[0]"; print "IP Address: $line[1]"; print "Root Server: $line[2]"; print "OS: $line[3]"; print "Last Report Time: $line[4]"; print "\n"; close $fh;