se strict; use warnings; #why negate, reverse the operations. Also, specifying STDIN is more self documenting. my $infile = @ARGV ? shift(@ARGV) : ; my $outfile = @ARGV ? shift(@ARGV) : ; handlefix($infile,$outfile); open(INFILE, '<', $infile) or die "\nCan't open $infile: $!\n"; open(OUTFILE, '>', $outfile) or die "\nCan't open $outfile: $!\n"; print OUTFILE map { my $s=$_; $s=~s/\s*#.*$//; $s } (grep { !/^\s*#/ } ), "\n" ; #close INFILE && close OUTFILE; close returns a value... if the first close fails Perl will ignore second close close INFILE; close OUTFILE; sub handlefix { for(@_){ chomp($_); $_=~s/"//g; $_=~s/\//\\/g; } } #### sub handlefix { my @return; for(@_){ my $val = $_; #decouple the value from the argument variable chomp($val); $val =~ s/"//g; $val =~ s/\//\\/g; } return @return; } ($infile,$outfile) = handlefix($infile,$outfile); #more obvious what is happening