#!/usr/bin/perl my $str = "123.0456.0789.0-WHOOPS"; my $sub = ".0"; print "str before = $str\n"; $str = rm_nth($str,$sub,2); print "str after = $str\n"; sub rm_nth { my ($str,$sub,$n) = @_; $n = 1 if $n < 1; my $p = -1; while ($n--) { $p = index($str,$sub,$p+1); return $str if $p < 0; } substr($str,$p,length($sub)) = ""; return $str; }