A lookahead can require nearby text without consuming it as part of the match.

Lookahead Guard

lookahead_guard.pl
use strict;
use warnings;

my $file = ;
my ($stem) = $file =~ /^([a-z]+)(?=\.csv$)/;
$stem = defined $stem ? $stem : "none";
my $csv = $stem ne "none" ? "yes" : "no";

print "file=$file\n";
print "stem=$stem\n";
print "csv=$csv\n";
use strict;
use warnings;

my $file = ;
my ($stem) = $file =~ /^([a-z]+)(?=\.csv$)/;
$stem = defined $stem ? $stem : "none";
my $csv = $stem ne "none" ? "yes" : "no";

print "file=$file\n";
print "stem=$stem\n";
print "csv=$csv\n";
use strict;
use warnings;

my $file = ;
my ($stem) = $file =~ /^([a-z]+)(?=\.csv$)/;
$stem = defined $stem ? $stem : "none";
my $csv = $stem ne "none" ? "yes" : "no";

print "file=$file\n";
print "stem=$stem\n";
print "csv=$csv\n";
lookahead Lookahead is useful when the program needs to confirm what comes next while keeping the matched text focused on the part being classified.