use strict; use warnings; my $pos = 21; my $str = "ABCDEFANABCDEFGHIJKLMNOPQRSTVVWXWZ"; my $pos_fan = rindex($str, "FAN", $pos); print substr($str, $pos_fan + 3, 3) . "\n"; #### ABC