Hi Sunita, Here's one way to do it
[code] use strict; use warnings; open my $fin, '<', 'data.txt' or die "Cannot open file ($!)"; open my $fout1, '>', 'output1.txt' or die "Cannot open file ($!)"; open my $fout2, '>', 'output2.txt' or die "Cannot open file ($!)"; while (<$fin>) { #Approach 1 using split my($num1, $num2) = split; #Approach 2 using regex (Uncomment to make it work) #my($num1, $num2) = /(\d+)\s+(\d+)/; print $fout1 "$num1 "; print $fout2 "$num2 "; } close $fout1; close $fout2; [/code] [input] 1 6 2 7 3 8 4 9 5 10 [/input] [output1.txt] 1 2 3 4 5 [/output1.txt] [output2.txt] 6 7 8 9 10 [/output2.txt] On Mon, Jul 7, 2014 at 1:48 PM, Sunita Pradhan < sunita.pradhan.2...@hotmail.com> wrote: > I have a file of contents: > ----------- > 1 6 > 2 7 > 3 8 > 4 9 > 5 10 > ---------- > I want a file with content: > > 1 2 3 4 5 > 6 7 8 9 10 > > -------- > I have written a few lines of following code but it does not work as > expected : > > ------------------------------------------- > #!/usr/bin/perl > use v5.10; > use strict; > use warnings; > > open(FILE, "numbers.txt") or die "can not open file . $!\n"; > open(FILE1, ">sumfile.txt") or die "can not open file . $!\n"; > > my @lines = <FILE>; > chomp @lines; > > my $c=0; > while ($c <= $#lines){ > if ($lines[$c] =~ /(\w+)\s+(\w+)/){ > print FILE1 "$1\n"; > print FILE1 "$2"; > > } > > $c++; > } > > close FILE; > close FILE1; > -------------------------- > > Please guide me . > -- best, Shaji ---------------------------------------------------------------------------------------------------------------------------------------------- Your talent is God's gift to you. What you do with it is your gift back to God. ----------------------------------------------------------------------------------------------------------------------------------------------