You don't need to use
$_, just use
$line from the first
foreach and use a different variable name for the second
foreach:
foreach $line (@words) {
$line =~ tr/A-Z/a-z/;
foreach $swear (@ignore) {
$line =~ s/$swear//;
}
}
But there is no need to do it nested. Just use two different loops. And I don't know about the relative merits of each, but if you want to lowercase a string, you can just use the Perl function
lc.