#! /usr/bin/perl -w -T use strict; my $str = 'foo_bar_foo_bar_12345'; print "$str\n"; $str =~ /(.*)(\1.*)/ || die "Failed!\n"; print "$2\n";