in reply to remove a comma

Quick and dirty, check if you're at the end of file:

use warnings; use strict; open my $fh, '<', 'file.txt' or die "can't open the damned file!: $!"; while (<$fh>){ chomp; if (! eof){ print "$_,\n"; } else { print "$_\n"; } }

Where 'file.txt' contains:

one two three

Output:

one, two, three