#!/usr/bin/perl use strict; use warnings; while () { if ( $_ =~ s/([?.,]$)/$1/){ print "$_ $1\n" }; } # puts ?., in a character class [] anchored at the # end $, and () captured to $1, a # regex internal variable. __DATA__ 4 score and 7 years ago? our forefathers came, upon a continent. foo bar bazz __END__