#!/usr/bin/perl use 5.016; use strict; use warnings; # 1042260 my $s='CHECK_ABC123_A1.txt'; if ( $s =~ m/^CHECK_(\w+)\.txt/ ) { say "\t \$1 is: $1\n\t and the regex matched the source string."; } else { say "\t Nope. Regex didn't match \$s."; } =head OUTPUT: $1 is: ABC123_A1 and the regex matched the source string. =cut