while (<>) { split /\|/; # Use of implicit split to @_ is deprecated my $output = "|"; foreach my $value (@_) { if ($value =~ m/"{1}/) { # equivalent to /"/, so does not do any counting $value =~ s/"//g; } $output =. $value . "|"; # should be .= } print $output; }