my $str = 'Goldman_Sachs_2002'; $str =~ s/_(?!\d*$)//g; print $str;