in reply to regex picking out a particular string

Works for me:
use strict; use warnings; my $string = "hello = 1234ab;cat;dog;4892"; my $semiColon=2; if ( $string =~ /hello.*=(\s*.*;\s*){$semiColon}(\s*.*;\s*).*/i ) { my $substring = $2; print "$substring\n"; }
I would recommend that you at least modify your dot-stars to be .*? (non-greedy). And get rid of the trailing one. That one's useless.
/hello.*?=(\s*.*?;\s*){$semiColon}(\s*.*?;\s*)/i

Caution: Contents may have been coded under pressure.