my $x = "\\\\files\\builds\\data\\M9998SBQCACSYD30401S"; if ($x =~ /Y\D\d+\D*$/){ print "This matches something, don't know if it's really what you want"; }