#!/usr/bin/perl -w use strict; my $myid = 'short test sequence'; my $myseq = 'CGGATACTGGGGACTAAGCAGCAGCAGCAGCAGCAGCAGTTT'; find_cag_repeat( $myid, $myseq ); sub find_cag_repeat { my ( $id, $seq ) = @_; if ( $seq =~ /((CAG){6,})/ ) { my $len = length($1); # the string matched within # the outer parentheses is stored # in memory and recalled # with $1 $id = substr( $id, 0, 20 ); print "Repeat with length $len found in $id\n"; } }