# if the current line is in $_ s/^|$/"/g; # if the current line is in $line $line =~ s/^|$/"/g; # or with [doc://substr] substr $_, 0, 0, '"'; substr $_, length $_, 0, '"'; # but it is simpler just to append a " $_ .= '"'; # or even $_ = '"' .$_ . '"';