open(TXTIN,"ARGV[0]") || die "Cannot open the data file"; open(TXTOUT,">ARGV[1]") || die "Cannot open the formatted file"; while(){ # gets a line from input file if( eof TXTIN ){ # eof returns true if the _next_ read would fail, meaning s/different/regex here/; # the one we just read was the last line }else{ s/yada/yadda/; } print TXTOUT $_; } close(TXTIN); close(TXTOUT);