in reply to codes error :(

Here's your problem:
foreach $motiffile(@motiffile){ if($motiffile =~ /(^[A|S]\d+\s+|^[A|S]\d+b\s+)([A-Z]+)(\s+.*)$ +/){ my $name = $1; my $site = $2; $regexp = IUB_to_regexp($site); $motif_hash{$name} = "$site $regexp\n"; print "motif : $site\n"; print "The regexp : $regexp\n"; } } return $regexp; ...
You start to loop through the array @motiffile, but as you get through to the end of this snippet, you return from the sub with one result, thus leaving the loop.

What you can do is collect all results, for example by using this instead of the return statement:

push @regexp, $regexp
(and of course, @regexp must be declared higher up in the sub), and after the loop block, return a combined regexp:
return join '|', @regexp;

update Oops, I misread the code (bad indentation), you return after the loop block, instead of in it... But the end result is nearly the same, except now you return the last $regexp instead of the first.

Put my push statement in the loop block.

Replies are listed 'Best First'.
A reply falls below the community's threshold of quality. You may see it by logging in.