my $string = "stash_ST1.2.3.4_1.ROLLBACK.check.20170228-101051.435944.txt"; # find one or more not "." between pair of "."s following word ROLLBACK my ($word) = $string =~ m/ROLLBACK\.([^\.]+)\./; print "$word\n"; # prints "check"