#!/usr/bin/perl -l use strict; use warnings; print 'Command line arg:'; print $ARGV[0]; my @parts = $ARGV[0] =~ /^(\w+)%(\d+)d[.](\w+)$/; print "Parts: @parts"; $parts[1] =~ s/^0*//; print "Parts (after stripping zeros): @parts"; my $re = qr{(?x: ^ $parts[0] \d{$parts[1]} [.] $parts[2] $ )}; print "Filter RE: $re"; my $glob_str = "$parts[0]*.$parts[2]"; print "Glob string: $glob_str"; print 'Found files:'; print for grep { /$re/ } glob $glob_str;