sub work_with_tmp_line { my ($message) = @_; if ( $message =~ /socketException/ ) { return 'NullPointerException'; } ... elsif ( $message =~ /Exception/ ) { return 'Exception'; } ... }