(my $version) = (m|(v?[\d\.]{2,})|g)[-1]; (my $version) = (m|/(v?[\d\.]{2,})|g)[-1]; #### #!/usr/bin/perl -w use strict; my @paths = qw ( '/tool/a/r/V2/V2DepCheck/1109.2.1/V2DepCheck.pm' '/tool/a/r/p4/r/main/V2/V2DepCheck/169441/V2DepCheck.pm' '/tool/a/r/p4/r/branches/bd32b/V2/V2DepCheck/175507/V2DepCheck.pm' '/home/me/cvs/V2/V2DepCheck.pm' '/tool/a/r/boost/1.36.0' '/tool/a/r/cadence/itk/itkvd/v007'); foreach (@paths) { chomp ; #not need here, use if reading from file #(my $version) = (m|tool/a/r.*?/(v?[\d.]{2,}).*$|i); (my $version) = (m|/(v?[\d\.]{2,}).*?$|); defined($version)? print "$version\n" : print "undefined\n"; } __END__ prints: 1109.2.1 169441 175507 undefined 1.36.0 v007