my $string = 'text1 text2 -f -DFLAG1 -global -DFLAG2 -DFLAG1'; my $pattern = '-D'; print substr($string, index($string, $pattern)), "\n";