#!/usr/bin/perl -w use strict; my $string= "ABCDEFGHIJKLMNOPCDEFQRST"; my $find="CDEF"; #extract first and last character my ($first, $last) = $find =~ /([A-Z])[A-Z]*([A-Z])/; #check both character present in string if ($string =~ /$first/ && $string =~ /$last/) { print "'$find' string found" if ($string =~ /$find/); }