I am trying to run the code what you have mentioned. But this is resulting in "List form of pipe open not implemented at...sort.pl line 19"(on my windows system).I came to know that "List form of pipe open "is not supported on windows system. and I changed it to open $fh, "|sort $filename", or die; and the entire code looks like this: use strict; use warnings; my $filename = "sort_input"; my $fh; my $line; my $key; my $value; my $prev_key; my $prev_value; my $file_consolidated_sort= "sort_output"; my $FH_sorting; #open $fh, '-|', 'sort', $filename or die; open $FH_sorting, ">>$file_consolidated_sort" or die "$!"; open $fh, "|sort $filename", or die; chomp( $line = <$fh> ); ($prev_key, $prev_value) = split /,,/, $line; while (<$fh>) { chomp; ($key, $value) = split /,,/; if ($prev_key eq $key) { $prev_value .= $value; } else { print $FH_sorting $prev_key ,, $prev_value; ($prev_key, $prev_value) = ($key, $value); } } print $FH_sorting $prev_key,,$prev_value; close $fh; close $FH_sorting; Another point is that I am not able to write the resulted output to the output file handler.All sorted output is getting printed on the screen itself with the warning/error on screen "Use of uninitialized value $line in chomp at line 25, 26 etc". I have not tried sorting with huge file(3GB) which is my actual requirement and have not tested for performance will improve or not. Parelelly I am looking into external sort