Thanks pvaldes and GrandFather,
I have tried both of your methods.
Both methods lead me to the same error:
syntax error at ./scriptfile line 55, near "if !~"
I should also have mentioned that the $TestFile also contains other options used in the script, which is initially the reason for why i used a foreach loop. here is the code if it helps any:
foreach $Line (<TESTFILE>) {
next if ($Line =~ m/^#/);
if ($Line =~ m/option1\s*=\s*(.*)/) {
$option1 = $1;
print "option1 = <$option1>\n";
}
if ($Line =~ m/option2\s*=\s*(.*)/) {
$option2 = $1;
print "option2 = <$option2>\n";
}
if ($Line =~ m/option3\s*=\s*(.*)/) {
$option3 = $1;
print "option3 = <$option3>\n";
}
if ($Line =~ m/option4\s*=\s*(.*)/) {
$option4 = $1;
print "option4 = <$option4>\n";
}
# if ($Line =~ m/To\s*=\s*(.*)/) {
# $To = $1;
# print "To = <$To>\n";
# }
if ($Line =~ m/option6\s*=\s*(.*)/) {
$option6 = $1;
print "option6 = <$option6>\n";
}
if ($Line =~ m/option7\s*=\s*(.*)/) {
$option7 = $1;
print "option7 = <$option7>\n";
}
if ($Line =~ m/option8\s*=\s*(.*)/) {
$option8 = $1;
print "option8 = <$option8>\n";
}
}
close(TESTFILE);