$url = q|$itemID|; #### #!/usr/bin/env perl use strict; use warnings; my $itemID = 'something-12345.html'; my $url = q|$itemID|; $url =~ /(\d{4,5})\.htm/i; print "Item ID: $itemID\n"; print " URL: $url\n"; my $num = $1; print " NUM: $1\n"; exit; #### #!/usr/bin/env perl use strict; use warnings; my $itemID = 'something-12345.html'; my $url = qq|$itemID|; $url =~ /(\d{4,5})\.htm/i; print "Item ID: $itemID\n"; print " URL: $url\n"; my $num = $1; print " NUM: $1\n"; exit; #### perl -MYAPE::Regex::Explain -E 'say YAPE::Regex::Explain->new("(\d{4})+\.htm")->explain();' #### The regular expression: (?-imsx:(d{4})+.htm) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1 (1 or more times (matching the most amount possible)): ---------------------------------------------------------------------- d{4} 'd' (4 times) ---------------------------------------------------------------------- )+ end of \1 (NOTE: because you are using a quantifier on this capture, only the LAST repetition of the captured pattern will be stored in \1) ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- htm 'htm' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- #### perl -MYAPE::Regex::Explain -E 'say YAPE::Regex::Explain->new("(\d{4,5})\.htm")->explain();' #### The regular expression: (?-imsx:(d{4,5}).htm) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- ( group and capture to \1: ---------------------------------------------------------------------- d{4,5} 'd' (between 4 and 5 times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of \1 ---------------------------------------------------------------------- . any character except \n ---------------------------------------------------------------------- htm 'htm' ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------