@all_listing = qw ('folder/file.000001.jpg','folder/file.000002.jpg', ... , 'folder/file.039000.jpg','folder/file.040000.jpg'); foreach $kk (@all_listing) { next if $kk eq ''; # next on empty line next if ($kk =~ m|(.+)\/\..+| and $hidden); # omit hidden (dot) files if ($kk =~ m|(.+)\/(\d+)\.(.+$)|) { # match image sequence without prefix $path = $1; $num = $2; $ext = $3; print "$path: $num.$ext\n" if ($debug); $pathpre = "$path/$ext"; # path and ext as the key ; adding ext so that if there are 2 seq with the same prefix and diff extension print ">> $pathpre\n" if ($debug); if (exists $seq{$pathpre}) { push (@range_tmp,$num); # add element to array } else { $seq{$pathpre} = $num; # create hash @range_tmp = $num; # empty array and add new element to it } $new_seq{$pathpre} = [@range_tmp]; # create new seq hash $ext{$pathpre} = $ext; # create hash of extension } elsif ($kk =~ m|(.+)\/(.+?)([\._]+)(\d+)\.(.+$)|) { # match image sequence $path = $1; $pre = $2; $div = $3 ; $num = $4; $ext = $5; print "$path: $pre$div$num.$ext\n" if ($debug); $pathpre = "$path/$pre$div$ext"; # path, prefix, divider and ext as the key ; adding ext so that if there are 2 seq with the same prefix and diff extension print ">> $pathpre\n" if ($debug); if (exists $seq{$pathpre}) { push (@range_tmp,$num); # add element to array } else { $seq{$pathpre} = $num; # create hash @range_tmp = $num; # empty array and add new element to it } $new_seq{$pathpre} = [@range_tmp]; # create new seq hash $ext{$pathpre} = $ext; # create hash of extension } elsif ($kk =~ m|(.+)\/(.+?)(\d+)\.(.+$)|) { # match most image sequence, except this 7R01.0118762.dpx (number before dot) ; above regex takes care of this match $path = $1; $pre = $2; $num = $3; $ext = $4; print "$path: $pre$num.$ext\n" if ($debug); $pathpre = "$path/$pre$ext"; # path, prefix and ext as the key ; adding ext so that if there are 2 seq with the same prefix and diff extension print ">> $pathpre\n" if ($debug); if (exists $seq{$pathpre}) { push (@range_tmp,$num); # add element to array } else { $seq{$pathpre} = $num; # create hash @range_tmp = $num; # empty array and add new element to it } $new_seq{$pathpre} = [@range_tmp]; # create new seq hash $ext{$pathpre} = $ext; # create hash of extension } else { push (@no_match,$kk); } }