#!/usr/bin/perl use warnings; use strict; my $string = "I have; in my string; replace all but last one;"; $string =~ s/;(?=.*;)//g; print $string;