$b='This_is_Sample_Text'; if ($b=~/^(.+)_[^_]+$/) { print "\n$1"; ## This_is_Sample }