my $string_exp = 'something in this string is a number. ${=NumberFormat "99999999"} is a number. And another ${=CharFormat "X*"} is ${=NumberFormat "9+"}.'; # remove the left curly bracket from the last NumberFormat placeholder in the above string my $placeholder = '${=CharFormat "X*"}'; print "$string_exp\n"; print "$placeholder\n"; if ( $string_exp =~ m/\Q$placeholder\E(.*)?(\$\{)|\z/ ) { print "\"$1\"\n"; } print "END\n";