if ($ARGV[0] =~ /^ep_svr_ (\d) # any single-digit number -- use (\d+) for multi-digits _([A-Za-z]{3}) # three letters _([A-Za-z]{3}) # three letters _(\w) # any "word" character -- use (.) for any character \z # if you want to anchor the end /x) { print "matched ",$ARGV[0],"\n"; my ($num,$alpha1,$alpha2,$char) = ($1,$2,$3,$4); # Do something with the captured parts here... }