Append to end of line
The $ character is used to do something from the end of a line. For example, let's say file.txt contains the text "Hello World". $ can be used to append to the end of the string. In this example, "Testing" is appended to the end of "Hello World".
$file = "/path/to/file.txt";
open(FH, '>>', $file) or die "cannot open $file";
while (<FH>) {
$_ =~ s|$|Testing|;
}
close(FH);
Replace end of line
The $ character is often used to replace text at the end of a line. In this example, lines ending with the word "World" are replaced with the word "Earth".
$file = "/path/to/file.txt";
open(FH, '>>', $file) or die "cannot open $file";
while (<FH>) {
$_ =~ s|World$|Earth|;
}
close(FH);