#!C:/perl/bin -w use strict; use vars qw ($input @input @img $img); @input = ; foreach $input (@input) { if ( $input =~ # Caret in next line: Start at begining of string/record/whatever /^(\d{6} # sTART CAPTURE, with any digit, [0-9], exactly six times. (- # optionally (trailing "?") in a NON-capture-group: a dash followed by a \w{3})? # word char, exactly 3 times; end grouping parens \.jpg$ # literal period followed by "jpg" ending the string ) # end capture /ix ) { #case insensitive (to catch -all and -EXP); extended form push(@img, $input); } } print "\n\t+++++\n"; print @img; print "\n\tdone\n"; exit; __DATA__ 012346.jpg 012346-all.jpg 012346-EXP.jpg 012346-exp.jpg 012346-ALL.jpg 012345.jpg 12345.jpg 01234.jpeg 0123345+ALL.jpg 0123345-exp.jpg 0123345-ALL.jpg not_jpg.last