Here is my code
my $filename = 'text.log';
my $items = "donkey";
open(my $fh, '<:encoding(UTF-8)', $filename) or die "Cant open";
while (my $contents = <$fh>)
{
print "$contents";
if ( $items =~m/$contents/)
{ print "Found $contents";}
else { print "NOTHING\n";}
}
Found $contents? What you've written can run, but it requires caution; you probably won't ever see anything except NOTHING. In particular, you're creating a new regex for each line — which probably isn't what you intend.donkey? The regex contains a newline which isn't in the$itemsstring, so the regex will never match. Even if you chomped the input line, you'd seldom have$contentsmatchingdonkey. You could typedonkey, ord..keyor such like, but mostly, running text won't match$items. If you[re writing a primitivegrepthat hunts fordonkey, then you have the regex expression back to front: you needif ($contents =~ m/$items/)as the condition. The explanation of what you're trying to do should be in the question, along with simple sample input (minimal reproducible example!).