while (<>) { next unless m{(\d+)/$}; my $temp = $1; ...use $temp... }