my $stuff; while () { if (/(...)(...)/) { # we have $1 and $2 in here, both some string } elsif (/(...)/) { $stuff = $1; } }