#!/usr/bin/perl use strict; use warnings; my $tofind="s"; my $replacement="X"; my $variable="snaskes"; print "Before: $variable\n"; $variable =~ s/$tofind[^$tofind]*$/$replacement/; # OR # $variable =~ s/$tofind(?![$tofind])$/$replacement/; print "After: $variable\n";
In reply to Re: Replace the last letter
by shemp
in thread Replace the last letter
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |