opendir(INDIR, $outdir) or die ("$indir not found\n"); while (my $infile = readdir(INDIR)) { chomp; next if $infile !~ /postpaid/; #change & to space for sorting purpose qx(cat $outdir/$infile |sed 's/\&/\t/g' > $outdir/$infile.tmp); #sort the data based on date or second colum qx(cat $outdir/$infile.tmp |sort -2 > $outdir/$infile.srt); #change back the space to & #NOTE: This one not working qx(cat $outdir/$infile.srt |sed 's/\t/\&/g' > $outdir/$infile.ok); #remove temporary file qx(rm -f $outdir/$infile.tmp); } closedir(INDIR);