# Web Development > PERL How to match multiline when reading input file line by line

## vishwaRam

Dear all,

I am doing QC Tool for XML Document. I need to generate error log with error(including line#,Col#).

How I am following is,




```
while($_ =~ m/<\/h>\n/msg)
{
       print "Err/line/Col";
}
```

*If I use undef $/ or $/="" means Can't get Line no/Col no of the Error. This is my actual Problem.* 

It's not working. It matches upto <\/h>\n only. Please suggest how to proceed.

Thanks in Advance.
vishwa Ram.

----------


## amitbhosale

hi,

the below attached  program resolves your following issue. 


Het blijvend beeld der Hollandse Kunst|1
De Bijbel in Holland's Schilder-cultuur|25

Some other text
Output file:

Some other text

Het blijvend beeld der Hollandse Kunst1

Some other text
##########################################
#!/usr/bin/perl
use strict;
use IO::File;

print "\n File operations";

my $source_file="/home/myprog/oldfile";
my $destination_file="/home/myprog/newfile";

my $input = IO::File->new("< $source_file") # open file in read mode
or die "Couldn't open $source_file for reading: $!\n";
my $output = IO::File->new("+> $destination_file") # open file for write mode
or die "Couldn't open $destination_file for reading: $!\n";

my $line;

while (defined($line = $input->getline())) {
chomp($line);

if ( $line =~ /^/ ) # if $line contain  then only execute following block of code
	{
	        print $output " \n"; # write  tag  in output file
            while ($line !~ /<\/tb>/) {

			$line=$input->getline(); # get next line of 

			STDOUT->print($line) if ($line =~ /^\w*\|*/);
			if ($line =~ s/\|/<\/ce>/g) { # search string | and replace with <\ce>
                        chomp($line);
                        print $output "$line \n"  #final string present in between ...
			}
		}
        print $output "\n"; # write close  tag in output file
	}
 else
	{
	 print $output "$line \n"  # write rest of the code as it is.
	}
}

$input->close();
$output->close();
##########################
output:
oldfile ===>
HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

Het blijvend beeld der Hollandse Kunst|1
De Bijbel in Holland's Schilder-cultuur|25

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

and 
newfile ===>

HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH

Het blijvend beeld der Hollandse Kunst1
De Bijbel in Holland's Schilder-cultuur25

TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT

----------

