#!/usr/bin/perl -w print "get some string: "; ($string = ); #note: chomp not necessary, $ should count \n as #end of string. should work with or without chomp. $string =~ m/\/([[:alnum:]]+)_.*\.(.+)$/; print "dollar 1: $1\n"; $type = $2; print "type: $type\n"; #something weird here.... $string =~ m/(.+)\.BBB$/; #get some string: /xxxx/yyyy/ZZZ_xxxx.CCC #dollar 1: ZZZ #type: CCC #dollar 1:ZZZ print "match failed\n" unless $string =~ m/(.+)\.BBB$/; #$string =~ m/(.+)\.${type}$/; #ok #$string =~ m/(.+)\.$type$/; #ok also print "dollar 1:$1\n"; exit 0; __END__ This is with the match failed code: C:\TEMP>regextest.pl get some string: /xxxx/yyyy/ZZZ_xxxx.CCC dollar 1: ZZZ type: CCC match failed dollar 1:ZZZ This is from: #$string =~ m/(.+)\.${type}$/; #ok #$string =~ m/(.+)\.$type$/; #ok also C:\TEMP>regextest.pl get some string: /xxxx/yyyy/ZZZ_xxxx.CCC dollar 1: ZZZ type: CCC dollar 1:/xxxx/yyyy/ZZZ_xxxx C:\TEMP>perl -v This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 registered patches, see perl -V for more detail)