$met_date = localtime(); open MS, ">mmonthlyreport.txt" or die "Can't open file"; format MS = @<<<<<<<<<<<<<<<<<<<<<<<< @#### @<< @<< @# @###### @##### Rs.@####.## ~ $consname, $consno, $subdvn, $tow, $phase, $chequeno, $receiptno, $amount . format MS_TOP = @|||||||||||||||||||||||||||||||||||| Pg @< "Monthly Meter Works Report", $% Date @<<<<<<<<<<<<<<<<<<<<<<< $met_date Consumer name CN. Sub. TOW Ph. Chq.no. RN Amt. -------------- ---- ---- --- --- ------- ---- ----- . format TOTAL = ----------------------------------------------------------------------------------- Rs@########.## $total Signature . open(MDAT, "; close(MDAT); $total = 0; foreach (@msrows) { chop(); ($consname, $consno, $subdvn, $tow, $phase, $chequeno, $receiptno, $amount) = (split(/!/)); $consname = "" if !defined($consname); $consno = 0 if !defined($consno); $subdvn = "" if !defined($subdvn); $tow = "" if !defined($tow); $phase = "" if !defined($phase); $chequeno = 0 if !defined($chequeno); $receiptno = 0 if !defined($receiptno); $amount= 0 if !defined($amount); if ($subdvn=='KP' && $tow=='RP' && $phase=='1' ) { my $kp = select(MS); $~ = "TOTAL"; select($kp); write(MS); close(MS); } } #### person1!8966!KP!RP!3!0!2043!4800.00 person2!9664!FA!RP!3!0!2044!4800.00 person3!1490!KP!RP!1!0!2045!1330.00 person4!1731!CH!RP!1!0!2046!1330.00 person5!3061!KP!RP!1!0!2047!1250.00 person6!0835!FB!RP!3!0!2048!4800.00