The line
$line =~ m/^(.*)$/
is misguided: all it does is put the contents of $line
into $1
, so the following statement
$myline = "\|$1"
may as well be
$myline = "|$line"
(The pipe |
doesn't need escaping unless it is part of a regular expression.)
Since you are printing $myline
at the end of your loop you are never seeing the contents of unmodified lines.
You can fix that by printing $line
or $myline
according to which one contains the required output, like this
while (my $line = <$fh>) {
chomp $line;
if ($line =~ m/^SID/) {
print "$line\n";
}
else {
my $myline = "|$line";
print "$myline\n";
}
}
or, much more simply, by dropping the intermediate variable and using the default $_
for the input lines, like this
while (<$fh>) {
print '|' unless /^SID/;
print;
}
Note that I have also removed the chomp
as it just means you have to put the newline back on the end of the string when you print it.